diff --git a/README.md b/README.md index 0799c48..bfd08e6 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This platform uses **Upbound DevEx** with: ## Overview This reference platform outlines a specialized API for generating an EKS cluster -([XCluster](apis/definition.yaml)) that incorporates XRs from the specified configurations: +([Cluster](apis/clusters/definition.yaml)) that incorporates XRs from the specified configurations: * [upbound-configuration-aws-lb-controller](https://github.com/upbound/configuration-aws-lb-controller) * [upbound-configuration-aws-network](https://github.com/upbound/configuration-aws-network) @@ -37,11 +37,11 @@ This reference platform outlines a specialized API for generating an EKS cluster ```mermaid graph LR; MyApp(My App)---MyCluster(XRC: my-cluster); - MyCluster---XRD1(XRD: XCluster); + MyCluster---XRD1(XRD: Cluster); MyApp---MyDB(XRC: my-db); MyDB---XRD2(XRD: XSQLInstance); subgraph Configuration:upbound/platform-ref-aws; - XRD1---Composition(XEKS, XNetwork, XAWSLBController, XFlux, XOss); + XRD1---Composition(EKS, Network, AWSLBController, Flux, Oss); XRD2---Composition2(Composition); end subgraph Provider:upbound/provider-aws @@ -90,7 +90,7 @@ up project build up test run tests/* # Render compositions with examples -up composition render apis/definition.yaml apis/composition.yaml examples/cluster-claim.yaml +up composition render apis/clusters/definition.yaml apis/clusters/composition.yaml examples/cluster/cluster.yaml ``` ## Using the Platform diff --git a/apis/composition.yaml b/apis/clusters/composition.yaml similarity index 74% rename from apis/composition.yaml rename to apis/clusters/composition.yaml index 0b98827..8c9d1cf 100644 --- a/apis/composition.yaml +++ b/apis/clusters/composition.yaml @@ -1,17 +1,17 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xclusters.aws.platformref.upbound.io + name: clusters.aws.platformref.upbound.io spec: writeConnectionSecretsToNamespace: crossplane-system compositeTypeRef: apiVersion: aws.platformref.upbound.io/v1alpha1 - kind: XCluster + kind: Cluster mode: Pipeline pipeline: - functionRef: - name: upbound-platform-ref-awsxcluster - step: xcluster + name: upbound-platform-ref-awscluster + step: cluster - functionRef: name: crossplane-contrib-function-auto-ready step: crossplane-contrib-function-auto-ready diff --git a/apis/clusters/definition.yaml b/apis/clusters/definition.yaml new file mode 100644 index 0000000..39e838e --- /dev/null +++ b/apis/clusters/definition.yaml @@ -0,0 +1,192 @@ +apiVersion: apiextensions.crossplane.io/v2 +kind: CompositeResourceDefinition +metadata: + name: clusters.aws.platformref.upbound.io +spec: + group: aws.platformref.upbound.io + names: + categories: + - crossplane + kind: Cluster + plural: clusters + scope: Namespaced + versions: + - name: v1alpha1 + referenceable: true + served: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + parameters: + type: object + description: Cluster configuration parameters. + properties: + clusterName: + type: string + description: The name of the cluster on the cloud platform. + id: + type: string + description: ID of this Cluster that other objects will use to refer to it. + region: + type: string + description: Region is the region you'd like your resource to be created in. + iam: + type: object + description: IAM configuration to connect as ClusterAdmin. + properties: + principalArn: + description: The IAM Principal ARN to connect as ClusterAdmin. + type: string + managementPolicies: + description: ManagementPolicies for AWS EC2 resources. Defaults to ["*"] which includes all operations (Create, Observe, Update, Delete, LateInitialize). To orphan resources on deletion, use ["Create", "Observe", "Update", "LateInitialize"]. + type: array + items: + type: string + enum: + - "*" + - Create + - Observe + - Update + - Delete + - LateInitialize + default: ["*"] + providerConfigName: + description: Crossplane ProviderConfig to use for provisioning this resources + type: string + default: default + version: + type: string + description: Kubernetes version of the Cluster + enum: + - "1.33" + - "1.32" + - "1.31" + default: "1.32" + nodes: + type: object + description: Cluster node configuration parameters. + properties: + count: + type: integer + description: Desired node count, from 1 to 100. + instanceType: + type: string + description: instance types associated with the Node Group. + default: t3.small + required: + - count + - instanceType + operators: + description: Configuration for operators. + type: object + default: + flux: + version: "2.10.6" + fluxSync: + version: "1.7.2" + prometheus: + version: "52.1.0" + properties: + flux: + description: Configuration for the Flux GitOps operator. + type: object + properties: + version: + description: flux helm-chart version to run. + type: string + default: "2.10.6" + required: + - version + fluxSync: + description: Configuration for the Flux Sync Helm-Chart. + type: object + properties: + version: + description: flux sync helm-chart version to run. + type: string + default: "1.7.2" + required: + - version + prometheus: + description: Configuration for the Prometheus Helm-Chart. + type: object + properties: + version: + description: prometheus helm-chart version to run. + type: string + default: "52.1.0" + required: + - version + gitops: + description: GitOps configure gitops system + type: object + properties: + git: + type: object + properties: + interval: + default: "5m0s" + description: Interval at which the GitRepository URL is checked for + updates. This interval is approximate and may be subject to jitter + to ensure efficient use of resources. + pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$ + type: string + timeout: + default: "60s" + description: Timeout for Git operations like cloning, defaults to + 60s. + pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$ + type: string + url: + description: URL specifies the Git repository URL, it can be an HTTP/S + or SSH address. + pattern: ^(http|https|ssh)://.*$ + type: string + path: + type: string + default: "/" + ref: + description: Reference specifies the Git reference to resolve and + monitor for changes. + type: object + properties: + name: + description: "Name of the reference to check out; takes precedence + over Branch, Tag and SemVer. \n It must be a valid Git reference: + https://git-scm.com/docs/git-check-ref-format#_description Examples: + \"refs/heads/main\", \"refs/tags/v0.1.0\", \"refs/pull/420/head\", + \"refs/merge-requests/1/head\"" + type: string + required: + - interval + - timeout + - url + - path + - ref + required: + - git + required: + - managementPolicies + - gitops + - id + - nodes + - operators + - providerConfigName + - region + required: + - parameters + status: + type: object + properties: + clusterName: + type: string + subnetIds: + type: array + items: + type: string + oidcProvider: + type: string \ No newline at end of file diff --git a/apis/definition.yaml b/apis/definition.yaml deleted file mode 100644 index bb7f631..0000000 --- a/apis/definition.yaml +++ /dev/null @@ -1,187 +0,0 @@ -apiVersion: apiextensions.crossplane.io/v1 -kind: CompositeResourceDefinition -metadata: - name: xclusters.aws.platformref.upbound.io -spec: - defaultCompositeDeletePolicy: Foreground - group: aws.platformref.upbound.io - names: - kind: XCluster - plural: xclusters - claimNames: - kind: Cluster - plural: clusters - versions: - - name: v1alpha1 - served: true - referenceable: true - schema: - openAPIV3Schema: - type: object - properties: - spec: - type: object - properties: - parameters: - type: object - description: Cluster configuration parameters. - properties: - clusterName: - type: string - description: The name of the cluster on the cloud platform. - id: - type: string - description: ID of this Cluster that other objects will use to refer to it. - region: - type: string - description: Region is the region you'd like your resource to be created in. - iam: - type: object - description: IAM configuration to connect as ClusterAdmin. - properties: - principalArn: - description: The IAM Principal ARN to connect as ClusterAdmin. - type: string - deletionPolicy: - description: Delete the external resources when the Claim/XR is deleted. Defaults to Delete - enum: - - Delete - - Orphan - type: string - default: Delete - providerConfigName: - description: Crossplane ProviderConfig to use for provisioning this resources - type: string - default: default - version: - type: string - description: Kubernetes version of the Cluster - enum: - - "1.33" - - "1.32" - - "1.31" - default: "1.32" - nodes: - type: object - description: Cluster node configuration parameters. - properties: - count: - type: integer - description: Desired node count, from 1 to 100. - instanceType: - type: string - description: instance types associated with the Node Group. - default: t3.small - required: - - count - - instanceType - operators: - description: Configuration for operators. - type: object - default: - flux: - version: "2.10.6" - fluxSync: - version: "1.7.2" - prometheus: - version: "52.1.0" - properties: - flux: - description: Configuration for the Flux GitOps operator. - type: object - properties: - version: - description: flux helm-chart version to run. - type: string - default: "2.10.6" - required: - - version - fluxSync: - description: Configuration for the Flux Sync Helm-Chart. - type: object - properties: - version: - description: flux sync helm-chart version to run. - type: string - default: "1.7.2" - required: - - version - prometheus: - description: Configuration for the Prometheus Helm-Chart. - type: object - properties: - version: - description: prometheus helm-chart version to run. - type: string - default: "52.1.0" - required: - - version - gitops: - description: GitOps configure gitops system - type: object - properties: - git: - type: object - properties: - interval: - default: "5m0s" - description: Interval at which the GitRepository URL is checked for - updates. This interval is approximate and may be subject to jitter - to ensure efficient use of resources. - pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$ - type: string - timeout: - default: "60s" - description: Timeout for Git operations like cloning, defaults to - 60s. - pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$ - type: string - url: - description: URL specifies the Git repository URL, it can be an HTTP/S - or SSH address. - pattern: ^(http|https|ssh)://.*$ - type: string - path: - type: string - default: "/" - ref: - description: Reference specifies the Git reference to resolve and - monitor for changes. - type: object - properties: - name: - description: "Name of the reference to check out; takes precedence - over Branch, Tag and SemVer. \n It must be a valid Git reference: - https://git-scm.com/docs/git-check-ref-format#_description Examples: - \"refs/heads/main\", \"refs/tags/v0.1.0\", \"refs/pull/420/head\", - \"refs/merge-requests/1/head\"" - type: string - required: - - interval - - timeout - - url - - path - - ref - required: - - git - required: - - deletionPolicy - - gitops - - id - - nodes - - operators - - providerConfigName - - region - required: - - parameters - status: - type: object - properties: - clusterName: - type: string - subnetIds: - type: array - items: - type: string - oidcProvider: - type: string diff --git a/examples/app-claim.yaml b/examples/app-claim.yaml index 2785bf9..523761f 100644 --- a/examples/app-claim.yaml +++ b/examples/app-claim.yaml @@ -6,9 +6,12 @@ metadata: labels: platform.upbound.io/deletion-ordering: enabled spec: - compositeDeletePolicy: Foreground parameters: helm: + chart: + name: ghost + repo: "https://charts.bitnami.com/bitnami" + version: 23.0.25 values: ingress: annotations: @@ -22,6 +25,4 @@ spec: providerConfigName: platform-ref-aws passwordSecretRef: namespace: default - name: platform-ref-aws-db-conn-mariadb - writeConnectionSecretToRef: - name: platform-ref-aws-ghost-conn + name: platform-ref-aws-db-mariadb-sql diff --git a/examples/cluster-claim.yaml b/examples/cluster-claim.yaml deleted file mode 100644 index 81c5868..0000000 --- a/examples/cluster-claim.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: aws.platformref.upbound.io/v1alpha1 -kind: Cluster -metadata: - annotations: - render.crossplane.io/composition-path: apis/pat/composition.yaml - render.crossplane.io/function-path: examples/functions.yaml - name: platform-ref-aws - namespace: default - labels: - platform.upbound.io/deletion-ordering: enabled -spec: - compositeDeletePolicy: Foreground - parameters: - id: platform-ref-aws - region: us-west-2 - version: "1.33" - #iam: - # replace with your custom arn like: - # principalArn: arn:aws:iam::123456789:role/AWSReservedSSO_AdministratorAccess_d703c73ed340fde7 - nodes: - count: 3 - instanceType: t3.small - operators: - flux: - version: "2.16.4" - fluxSync: - version: "1.13.4" - prometheus: - version: "76.3.0" - gitops: - git: - interval: "5m0s" - timeout: "60s" - url: https://github.com/upbound/platform-ref-aws/ - path: "/" - ref: - # refs/heads/main - # refs/tags/v0.1.0 - # refs/pull/420/head - # refs/merge-requests/1/head - name: refs/heads/main - writeConnectionSecretToRef: - name: platform-ref-aws-kubeconfig diff --git a/examples/xcluster.yaml b/examples/cluster/cluster.yaml similarity index 77% rename from examples/xcluster.yaml rename to examples/cluster/cluster.yaml index b111d8c..0469045 100644 --- a/examples/xcluster.yaml +++ b/examples/cluster/cluster.yaml @@ -1,21 +1,15 @@ apiVersion: aws.platformref.upbound.io/v1alpha1 -kind: XCluster +kind: Cluster metadata: name: platform-ref-aws namespace: default labels: platform.upbound.io/deletion-ordering: enabled spec: - compositeDeletePolicy: Foreground - writeConnectionSecretToRef: - name: platform-ref-aws-kubeconfig - namespace: default parameters: id: platform-ref-aws region: us-west-2 version: "1.32" - networkSelector: basic - deletionPolicy: Delete providerConfigName: default nodes: count: 3 diff --git a/examples/mariadb-claim.yaml b/examples/mariadb-claim.yaml index 20e1817..929b183 100644 --- a/examples/mariadb-claim.yaml +++ b/examples/mariadb-claim.yaml @@ -11,10 +11,7 @@ spec: storageGB: 5 autoGeneratePassword: true passwordSecretRef: - namespace: default name: mariadbsecret key: password networkRef: id: platform-ref-aws - writeConnectionSecretToRef: - name: platform-ref-aws-db-conn-mariadb diff --git a/functions/xcluster/kcl.mod b/functions/cluster/kcl.mod similarity index 100% rename from functions/xcluster/kcl.mod rename to functions/cluster/kcl.mod diff --git a/functions/cluster/kcl.mod.lock b/functions/cluster/kcl.mod.lock new file mode 100644 index 0000000..2063f93 --- /dev/null +++ b/functions/cluster/kcl.mod.lock @@ -0,0 +1,5 @@ +[dependencies] + [dependencies.models] + name = "models" + full_name = "models_0.0.1" + version = "0.0.1" diff --git a/functions/xcluster/main.k b/functions/cluster/main.k similarity index 58% rename from functions/xcluster/main.k rename to functions/cluster/main.k index 7f893e7..a94a332 100644 --- a/functions/xcluster/main.k +++ b/functions/cluster/main.k @@ -8,42 +8,38 @@ _ocds = option("params").ocds _dxr = option("params").dxr dcds = option("params").dcds +params = oxr.spec.parameters +uid = oxr.metadata?.uid + +_defaults = { + managementPolicies = params.managementPolicies or ["*"] + providerConfigName = params.providerConfigName +} + _metadata = lambda name: str -> any { { annotations = { "krm.kcl.dev/composition-resource-name" = name }} } -# Extract parameters from the observed XR -id = oxr.spec?.parameters?.id -region = oxr.spec?.parameters?.region -version = oxr.spec?.parameters?.version -nodes = oxr.spec?.parameters?.nodes -iam = oxr.spec?.parameters?.iam -deletionPolicy = oxr.spec?.parameters?.deletionPolicy -providerConfigName = oxr.spec?.parameters?.providerConfigName -operators = oxr.spec?.parameters?.operators -gitops = oxr.spec?.parameters?.gitops -uid = oxr.metadata?.uid - # Connection secret name -connectionSecretName = id + "-eks" +connectionSecretName = params.id + "-eks" -# Try to get VPC ID from observed XNetwork status -_observedVpcId = _ocds?["XNetwork"]?.Resource?.status?.vpcId +# Try to get VPC ID from observed Network status +_observedVpcId = _ocds?["Network"]?.Resource?.status?.vpcId -# Check if XEKS is ready before creating any Helm releases (they all need kubeconfig) -_eksReadyCondition = [condition for condition in (_ocds?["XEKS"]?.Resource?.status?.conditions or []) if condition.type == "Ready" and condition.status == "True"] +# Check if EKS is ready before creating any Helm releases (they all need kubeconfig) +_eksReadyCondition = [condition for condition in (_ocds?["EKS"]?.Resource?.status?.conditions or []) if condition.type == "Ready" and condition.status == "True"] _isEksReady = len(_eksReadyCondition) > 0 -# Check if XAWSLBController already exists (safety check to prevent uninstalling) -_lbControllerExists = "XAWSLBController" in _ocds +# Check if AWSLBController already exists (safety check to prevent uninstalling) +_lbControllerExists = "AWSLBController" in _ocds -# Check if XAWSLBController is ready before creating Flux and OSS (to avoid webhook conflicts) -_lbControllerReadyCondition = [condition for condition in (_ocds?["XAWSLBController"]?.Resource?.status?.conditions or []) if condition.type == "Ready" and condition.status == "True"] +# Check if AWSLBController is ready before creating Flux and OSS (to avoid webhook conflicts) +_lbControllerReadyCondition = [condition for condition in (_ocds?["AWSLBController"]?.Resource?.status?.conditions or []) if condition.type == "Ready" and condition.status == "True"] _isLbControllerReady = len(_lbControllerReadyCondition) > 0 # Check if dependent resources already exist (safety checks to prevent uninstalling) -_ossExists = "XOss" in _ocds -_fluxExists = "XFlux" in _ocds +_ossExists = "Oss" in _ocds +_fluxExists = "Flux" in _ocds # Generate region-specific availability zones for subnets _regionAzMap = { @@ -60,7 +56,7 @@ _regionAzMap = { "ca-central-1": ["ca-central-1a", "ca-central-1b"] } -_availabilityZones = _regionAzMap[region] if region in _regionAzMap else ["us-west-2a", "us-west-2b"] +_availabilityZones = _regionAzMap[params.region] if params.region in _regionAzMap else ["us-west-2a", "us-west-2b"] # Generate subnets configuration based on the region's availability zones _regionSpecificSubnets = [ @@ -87,135 +83,126 @@ _regionSpecificSubnets = [ ] _items = [ - # XNetwork resource - awsplatformv1alpha1.XNetwork { - metadata: _metadata("XNetwork") | { - name = id + "-network" + # Network resource + awsplatformv1alpha1.Network { + metadata: _metadata("Network") | { + name = params.id + "-network" } spec: { - parameters: { - id = id - region = region - deletionPolicy = deletionPolicy - providerConfigName = providerConfigName + parameters: _defaults | { + id = params.id + region = params.region subnets = _regionSpecificSubnets } } } - # XEKS resource - awsplatformv1alpha1.XEKS { - metadata: _metadata("XEKS") | { - name = id + "-eks" + # EKS resource + awsplatformv1alpha1.EKS { + metadata: _metadata("EKS") | { + name = params.id + "-eks" labels: { "platform.upbound.io/deletion-ordering" = oxr.metadata?.labels?["platform.upbound.io/deletion-ordering"] } annotations: { - "crossplane.io/external-name" = id + "crossplane.io/external-name" = params.id } } spec: { - parameters: { - id = id - region = region - deletionPolicy = deletionPolicy - providerConfigName = providerConfigName - version = version - nodes = nodes - } | ({iam = iam} if iam else {}) - writeConnectionSecretToRef: { - name = connectionSecretName - namespace = "crossplane-system" - } + parameters: _defaults | { + id = params.id + region = params.region + version = params.version + nodes = params.nodes + } | ({iam = params.iam} if params.iam else {}) } } - # XAWSLBController resource - only create when XEKS is ready (needs kubeconfig secret) + # AWSLBController resource - only create when EKS is ready (needs kubeconfig secret) # Also create if it already exists to prevent uninstalling if _isEksReady or _lbControllerExists: - awsplatformv1alpha1.XAWSLBController { - metadata: _metadata("XAWSLBController") | { - name = id + "-lb-controller" + awsplatformv1alpha1.AWSLBController { + metadata: _metadata("AWSLBController") | { + name = params.id + "-lb-controller" } spec: { parameters: { - providerConfigName = providerConfigName - deletionPolicy = deletionPolicy + providerConfigName = params.providerConfigName helm: { - providerConfigName = id + providerConfigName = params.id } - region = region + region = params.region clusterNameSelector = { matchLabels = { - "crossplane.io/claim-name" = id + "crossplane.io/claim-name" = params.id } if oxr.spec?.claimRef?.name else { - "crossplane.io/composite" = id + "crossplane.io/composite" = params.id } } # Pass VPC ID if available to avoid EC2 metadata discovery if _observedVpcId: vpcId = _observedVpcId + managementPolicies = params.managementPolicies or ["*"] } } } - # XOss resource - only create when LB Controller is ready (to avoid webhook conflicts) + # Oss resource - only create when LB Controller is ready (to avoid webhook conflicts) # Also create if it already exists to prevent uninstalling if _isLbControllerReady or _ossExists: - observev1alpha1.XOss { - metadata: _metadata("XOss") | { - name = id + "-oss" + observev1alpha1.Oss { + metadata: _metadata("Oss") | { + name = params.id + "-oss" } spec: { parameters: { - deletionPolicy = deletionPolicy - id = id + id = params.id operators: { - prometheus = operators?.prometheus + prometheus = params.operators?.prometheus } + managementPolicies = params.managementPolicies or ["*"] } } } - # XFlux resource - only create when LB Controller is ready (to avoid webhook conflicts) + # Flux resource - only create when LB Controller is ready (to avoid webhook conflicts) # Also create if it already exists to prevent uninstalling if _isLbControllerReady or _fluxExists: - gitopsv1alpha1.XFlux { - metadata: _metadata("XFlux") | { - name = id + "-flux" + gitopsv1alpha1.Flux { + metadata: _metadata("Flux") | { + name = params.id + "-flux" } spec: { - parameters: { - deletionPolicy = deletionPolicy - providerConfigName = id + parameters: _defaults | { + providerConfigName = params.id operators: { - flux = operators?.flux - fluxSync = operators?.fluxSync + flux = params.operators?.flux + fluxSync = params.operators?.fluxSync } - source = gitops + source = params.gitops } } } # Usage resources for dependency management (untyped objects) { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXNetworkByXEKS") | { - name = id + "-network-by-eks" + metadata: _metadata("usageXNetworkByEKS") | { + name = params.id + "-network-by-eks" } spec: { replayDeletion = True by: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XEKS" + kind = "EKS" resourceSelector: { matchControllerRef = True } } of: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XNetwork" + kind = "Network" resourceSelector: { matchControllerRef = True } @@ -224,23 +211,23 @@ _items = [ } { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXEksByXFlux") | { - name = id + "-eks-by-flux" + metadata: _metadata("usageXEksByFlux") | { + name = params.id + "-eks-by-flux" } spec: { replayDeletion = True by: { apiVersion = "gitops.platform.upbound.io/v1alpha1" - kind = "XFlux" + kind = "Flux" resourceSelector: { matchControllerRef = True } } of: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XEKS" + kind = "EKS" resourceSelector: { matchControllerRef = True } @@ -249,23 +236,23 @@ _items = [ } { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXEksByXOss") | { - name = id + "-eks-by-oss" + metadata: _metadata("usageXEksByOss") | { + name = params.id + "-eks-by-oss" } spec: { replayDeletion = True by: { apiVersion = "observe.platform.upbound.io/v1alpha1" - kind = "XOss" + kind = "Oss" resourceSelector: { matchControllerRef = True } } of: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XEKS" + kind = "EKS" resourceSelector: { matchControllerRef = True } @@ -274,10 +261,10 @@ _items = [ } { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXEksByArbitraryLabeledRelease") | { - name = id + "-eks-by-labeled-release" + metadata: _metadata("usageEksByArbitraryLabeledRelease") | { + name = params.id + "-eks-by-labeled-release" annotations = { "krm.kcl.dev/ready": "True" } @@ -295,7 +282,7 @@ _items = [ } of: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XEKS" + kind = "EKS" resourceSelector: { matchControllerRef = True } @@ -304,10 +291,10 @@ _items = [ } { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXAWSLBControllerByArbitraryLabeledApp") | { - name = id + "-lb-controller-by-labeled-app" + metadata: _metadata("usageAWSLBControllerByArbitraryLabeledApp") | { + name = params.id + "-lb-controller-by-labeled-app" annotations = { "krm.kcl.dev/ready": "True" } @@ -325,7 +312,7 @@ _items = [ } of: { apiVersion = "aws.platform.upbound.io/v1alpha1" - kind = "XAWSLBController" + kind = "AWSLBController" resourceSelector: { matchControllerRef = True } @@ -333,12 +320,12 @@ _items = [ } } - # Usage resource to ensure XFlux is deleted before XAWSLBController + # Usage resource to ensure Flux is deleted before AWSLBController { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" - metadata: _metadata("usageXAWSLBControllerByXFlux") | { - name = id + "-lb-controller-by-flux" + metadata: _metadata("usageAWSLBControllerByFlux") | { + name = params.id + "-lb-controller-by-flux" annotations = { "krm.kcl.dev/ready": "True" } @@ -347,14 +334,14 @@ _items = [ replayDeletion = True by: { apiVersion: "gitops.platform.upbound.io/v1alpha1" - kind: "XFlux" + kind: "Flux" resourceSelector: { matchControllerRef = True } } of: { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XAWSLBController" + kind: "AWSLBController" resourceSelector: { matchControllerRef = True } @@ -362,13 +349,13 @@ _items = [ } } - # Forward connection details from XEKS + # Forward connection details from EKS { apiVersion: "meta.krm.kcl.dev/v1alpha1" kind: "CompositeConnectionDetails" - if "XEKS" in _ocds: + if "EKS" in _ocds: data: { - kubeconfig = _ocds["XEKS"].ConnectionDetails.kubeconfig + kubeconfig = _ocds["EKS"].ConnectionDetails.kubeconfig } else: data: {} diff --git a/functions/xcluster/model b/functions/cluster/model similarity index 100% rename from functions/xcluster/model rename to functions/cluster/model diff --git a/functions/xcluster/kcl.mod.lock b/functions/xcluster/kcl.mod.lock deleted file mode 100644 index 7756095..0000000 --- a/functions/xcluster/kcl.mod.lock +++ /dev/null @@ -1,12 +0,0 @@ -[dependencies] - [dependencies.model] - name = "model" - full_name = "models_0.0.1" - version = "0.0.1" - reg = "ghcr.io" - repo = "kcl-lang/model" - oci_tag = "0.0.1" - [dependencies.models] - name = "models" - full_name = "models_0.0.1" - version = "0.0.1" diff --git a/tests/e2etest-xcluster/kcl.mod b/tests/e2etest-cluster/kcl.mod similarity index 73% rename from tests/e2etest-xcluster/kcl.mod rename to tests/e2etest-cluster/kcl.mod index 5912d60..f10912d 100644 --- a/tests/e2etest-xcluster/kcl.mod +++ b/tests/e2etest-cluster/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "e2etest-xcluster" +name = "e2etest-cluster" version = "0.0.1" [dependencies] diff --git a/tests/e2etest-cluster/kcl.mod.lock b/tests/e2etest-cluster/kcl.mod.lock new file mode 100644 index 0000000..2063f93 --- /dev/null +++ b/tests/e2etest-cluster/kcl.mod.lock @@ -0,0 +1,5 @@ +[dependencies] + [dependencies.models] + name = "models" + full_name = "models_0.0.1" + version = "0.0.1" diff --git a/tests/e2etest-xcluster/main.k b/tests/e2etest-cluster/main.k similarity index 62% rename from tests/e2etest-xcluster/main.k rename to tests/e2etest-cluster/main.k index 09d5281..55bf1dd 100644 --- a/tests/e2etest-xcluster/main.k +++ b/tests/e2etest-cluster/main.k @@ -1,32 +1,33 @@ -import models.io.upbound.aws.v1beta1 as awsv1beta1 +import models.io.upbound.awsm.v1beta1 as awsv1beta1 import models.io.upbound.dev.meta.v1alpha1 as metav1alpha1 import models.io.upbound.platform.aws.v1alpha1 as platformawsv1alpha1 import models.io.upbound.platform.v1alpha1 as platformv1alpha1 import models.io.upbound.platformref.aws.v1alpha1 as platformrefawsv1alpha1 +import models.io.crossplane.pkg.v1 as pkgv1 _items = [ metav1alpha1.E2ETest{ metadata.name: "e2etest-cluster" spec= { - crossplane.autoUpgrade.channel: "Rapid" + crossplane.autoUpgrade.channel: "None" + crossplane.version = "2.0.2-up.5" defaultConditions: ["Ready"] manifests: [ - # XCluster test instance (XR) - platformrefawsv1alpha1.XCluster{ + # Cluster test instance (XR) + platformrefawsv1alpha1.Cluster{ metadata= { name: "test-cluster-e2e" + namespace: "default" labels: { "platform.upbound.io/deletion-ordering": "enabled" } } spec= { - compositionUpdatePolicy: "Automatic" parameters= { id: "test-cluster-e2e" region: "eu-central-1" version: "1.33" - deletionPolicy: "Delete" providerConfigName: "default" nodes= { count: 3 # Single node is not enough for e2e test with lb-controller and rest of the helm charts @@ -55,27 +56,24 @@ _items = [ } } } - writeConnectionSecretToRef: { - name: "platform-ref-aws-kubeconfig" - namespace: "crossplane-system" - } } }, # 2. Database XR (MariaDB) - platformawsv1alpha1.XSQLInstance{ + platformawsv1alpha1.SQLInstance{ metadata = { name: "test-cluster-e2e-db-mariadb" + namespace: "default" } spec = { parameters = { + providerConfigName: "default" region: "eu-central-1" engine: "mariadb" engineVersion: "10.11.14" storageGB: 5 autoGeneratePassword: True passwordSecretRef = { - namespace: "default" name: "mariadbsecret" key: "password" } @@ -83,27 +81,28 @@ _items = [ id: "test-cluster-e2e" } } - writeConnectionSecretToRef = { - name: "test-cluster-e2e-db-conn-mariadb" - namespace: "crossplane-system" - } } }, # 3. App XR (Ghost blog application) - platformv1alpha1.XApp{ + platformv1alpha1.App{ metadata = { name: "test-cluster-e2e-ghost" + namespace: "default" labels = { "platform.upbound.io/deletion-ordering": "enabled" } } spec = { - compositionUpdatePolicy: "Automatic" parameters = { providerConfigName: "test-cluster-e2e" helm = { wait: False + chart = { + name: "ghost" + repo: "https://charts.bitnami.com/bitnami" + version: "21.1.18" + } values = { ingress = { annotations = { @@ -119,84 +118,31 @@ _items = [ } } passwordSecretRef = { - namespace: "crossplane-system" - name: "test-cluster-e2e-db-conn-mariadb" + name: "test-cluster-e2e-db-mariadb-sql" + namespace: "default" } } - writeConnectionSecretToRef = { - name: "test-cluster-e2e-app-conn" - namespace: "crossplane-system" - } } } ] - initResources = [ - # Workaround for the e2e test early failure when providers are not ready - # AWS Provider Family - { - apiVersion: "pkg.crossplane.io/v1" - kind: "Provider" + initResources: [ + # Provider family for AWS (workaround for ProviderConfig RBAC) + pkgv1.Provider { metadata = { name: "upbound-provider-family-aws" } spec = { - package: "xpkg.upbound.io/upbound/provider-family-aws:v1.23.2" - packagePullPolicy: "Always" - } - }, - # AWS EC2 Provider - { - apiVersion: "pkg.crossplane.io/v1" - kind: "Provider" - metadata = { - name: "upbound-provider-aws-ec2" - } - spec = { - package: "xpkg.upbound.io/upbound/provider-aws-ec2:v1.23.2" - packagePullPolicy: "Always" - } - }, - # AWS EKS Provider - { - apiVersion: "pkg.crossplane.io/v1" - kind: "Provider" - metadata = { - name: "upbound-provider-aws-eks" - } - spec = { - package: "xpkg.upbound.io/upbound/provider-aws-eks:v1.23.2" - packagePullPolicy: "Always" - } - }, - # AWS IAM Provider - { - apiVersion: "pkg.crossplane.io/v1" - kind: "Provider" - metadata = { - name: "upbound-provider-aws-iam" - } - spec = { - package: "xpkg.upbound.io/upbound/provider-aws-iam:v1.23.2" - packagePullPolicy: "Always" - } - }, - # AWS RDS Provider - { - apiVersion: "pkg.crossplane.io/v1" - kind: "Provider" - metadata = { - name: "upbound-provider-aws-rds" - } - spec = { - package: "xpkg.upbound.io/upbound/provider-aws-rds:v1.23.2" - packagePullPolicy: "Always" + package: "xpkg.upbound.io/upbound/provider-family-aws:v2.3.0" } } ] extraResources = [ # AWS ProviderConfig for AWS resources awsv1beta1.ProviderConfig{ - metadata.name = "default" + metadata = { + name = "default" + namespace = "default" + } spec = { credentials = { source = "Upbound" diff --git a/tests/e2etest-xcluster/model b/tests/e2etest-cluster/model similarity index 100% rename from tests/e2etest-xcluster/model rename to tests/e2etest-cluster/model diff --git a/tests/e2etest-xcluster/kcl.mod.lock b/tests/e2etest-xcluster/kcl.mod.lock deleted file mode 100644 index 7756095..0000000 --- a/tests/e2etest-xcluster/kcl.mod.lock +++ /dev/null @@ -1,12 +0,0 @@ -[dependencies] - [dependencies.model] - name = "model" - full_name = "models_0.0.1" - version = "0.0.1" - reg = "ghcr.io" - repo = "kcl-lang/model" - oci_tag = "0.0.1" - [dependencies.models] - name = "models" - full_name = "models_0.0.1" - version = "0.0.1" diff --git a/tests/test-cluster/kcl.mod.lock b/tests/test-cluster/kcl.mod.lock index 7756095..2063f93 100644 --- a/tests/test-cluster/kcl.mod.lock +++ b/tests/test-cluster/kcl.mod.lock @@ -1,11 +1,4 @@ [dependencies] - [dependencies.model] - name = "model" - full_name = "models_0.0.1" - version = "0.0.1" - reg = "ghcr.io" - repo = "kcl-lang/model" - oci_tag = "0.0.1" [dependencies.models] name = "models" full_name = "models_0.0.1" diff --git a/tests/test-cluster/main.k b/tests/test-cluster/main.k index c5dd9e4..930943b 100644 --- a/tests/test-cluster/main.k +++ b/tests/test-cluster/main.k @@ -7,18 +7,17 @@ import models.io.upbound.platformref.aws.v1alpha1 as platformrefawsv1alpha1 _items = [ metav1alpha1.CompositionTest{ - metadata.name: "test-xcluster" + metadata.name: "test-cluster" spec = { assertResources: [ - # XCluster for main composite resource - platformrefawsv1alpha1.XCluster{ + # Cluster for main composite resource + platformrefawsv1alpha1.Cluster{ metadata.name: "platform-ref-aws" spec = { parameters = { id: "platform-ref-aws" region: "us-west-2" version: "1.32" - deletionPolicy: "Delete" providerConfigName: "default" nodes = { count: 3 @@ -46,17 +45,18 @@ _items = [ } } } + } } } - # XNetwork for AWS networking - awsplatformv1alpha1.XNetwork{ + # Network for AWS networking + awsplatformv1alpha1.Network{ metadata.name: "platform-ref-aws-network" spec = { parameters = { id: "platform-ref-aws" region: "us-west-2" - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "default" subnets = [ { @@ -83,8 +83,8 @@ _items = [ } } }, - # XEKS for Amazon EKS - awsplatformv1alpha1.XEKS{ + # EKS for Amazon EKS + awsplatformv1alpha1.EKS{ metadata = { name: "platform-ref-aws-eks" labels = { @@ -98,7 +98,7 @@ _items = [ parameters = { id: "platform-ref-aws" region: "us-west-2" - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "default" version: "1.32" nodes = { @@ -106,18 +106,14 @@ _items = [ instanceType: "t3.small" } } - writeConnectionSecretToRef = { - name: "platform-ref-aws-eks" - namespace: "crossplane-system" - } } }, - # XOss for observability stack - observev1alpha1.XOss{ + # Oss for observability stack + observev1alpha1.Oss{ metadata.name: "platform-ref-aws-oss" spec = { parameters = { - deletionPolicy: "Delete" + managementPolicies: ["*"] id: "platform-ref-aws" operators = { prometheus = { @@ -127,12 +123,12 @@ _items = [ } } }, - # XFlux for GitOps - gitopsv1alpha1.XFlux{ + # Flux for GitOps + gitopsv1alpha1.Flux{ metadata.name: "platform-ref-aws-flux" spec = { parameters = { - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "platform-ref-aws" operators = { flux = { @@ -156,13 +152,13 @@ _items = [ } } }, - # XAWSLBController for Load Balancer Controller - awsplatformv1alpha1.XAWSLBController{ + # AWSLBController for Load Balancer Controller + awsplatformv1alpha1.AWSLBController{ metadata.name: "platform-ref-aws-lb-controller" spec = { parameters = { providerConfigName: "default" - deletionPolicy: "Delete" + managementPolicies: ["*"] helm = { providerConfigName: "platform-ref-aws" } @@ -178,21 +174,21 @@ _items = [ }, # Usage resources for dependency management (untyped objects) { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-network-by-eks" spec = { replayDeletion: True by = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XEKS" + kind: "EKS" resourceSelector = { matchControllerRef: True } } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XNetwork" + kind: "Network" resourceSelector = { matchControllerRef: True } @@ -200,21 +196,21 @@ _items = [ } }, { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-eks-by-flux" spec = { replayDeletion: True by = { apiVersion: "gitops.platform.upbound.io/v1alpha1" - kind: "XFlux" + kind: "Flux" resourceSelector = { matchControllerRef: True } } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XEKS" + kind: "EKS" resourceSelector = { matchControllerRef: True } @@ -222,21 +218,21 @@ _items = [ } }, { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-eks-by-oss" spec = { replayDeletion: True by = { apiVersion: "observe.platform.upbound.io/v1alpha1" - kind: "XOss" + kind: "Oss" resourceSelector = { matchControllerRef: True } } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XEKS" + kind: "EKS" resourceSelector = { matchControllerRef: True } @@ -244,7 +240,7 @@ _items = [ } }, { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-eks-by-labeled-release" spec = { @@ -260,7 +256,7 @@ _items = [ } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XEKS" + kind: "EKS" resourceSelector = { matchControllerRef: True } @@ -268,7 +264,7 @@ _items = [ } }, { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-lb-controller-by-labeled-app" spec = { @@ -284,7 +280,7 @@ _items = [ } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XAWSLBController" + kind: "AWSLBController" resourceSelector = { matchControllerRef: True } @@ -292,21 +288,21 @@ _items = [ } }, { - apiVersion: "apiextensions.crossplane.io/v1alpha1" + apiVersion: "protection.crossplane.io/v1beta1" kind: "Usage" metadata.name: "platform-ref-aws-lb-controller-by-flux" spec = { replayDeletion: True by = { apiVersion: "gitops.platform.upbound.io/v1alpha1" - kind: "XFlux" + kind: "Flux" resourceSelector = { matchControllerRef: True } } of = { apiVersion: "aws.platform.upbound.io/v1alpha1" - kind: "XAWSLBController" + kind: "AWSLBController" resourceSelector = { matchControllerRef: True } @@ -315,19 +311,19 @@ _items = [ } ] observedResources: [ - # XNetwork with VPC ID in status - awsplatformv1alpha1.XNetwork{ + # Network with VPC ID in status + awsplatformv1alpha1.Network{ metadata = { name: "platform-ref-aws-network" annotations = { - "crossplane.io/composition-resource-name" = "XNetwork" + "crossplane.io/composition-resource-name" = "Network" } } spec = { parameters = { id: "platform-ref-aws" region: "us-west-2" - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "default" subnets = [ { @@ -352,27 +348,22 @@ _items = [ } ] } - compositionSelector = { - matchLabels = { - type: "basic" - } - } } status = { vpcId: "vpc-test123" } }, - # XFlux with Ready condition to trigger XAWSLBController creation - gitopsv1alpha1.XFlux{ + # Flux with Ready condition to trigger AWSLBController creation + gitopsv1alpha1.Flux{ metadata = { name: "platform-ref-aws-flux" annotations = { - "crossplane.io/composition-resource-name" = "XFlux" + "crossplane.io/composition-resource-name" = "Flux" } } spec = { parameters = { - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "platform-ref-aws" operators = { flux = { @@ -406,19 +397,19 @@ _items = [ ] } }, - # XEKS with Ready condition to trigger all Helm releases creation - awsplatformv1alpha1.XEKS{ + # EKS with Ready condition to trigger all Helm releases creation + awsplatformv1alpha1.EKS{ metadata = { name: "platform-ref-aws-eks" annotations = { - "crossplane.io/composition-resource-name" = "XEKS" + "crossplane.io/composition-resource-name" = "EKS" } } spec = { parameters = { id: "platform-ref-aws" region: "us-west-2" - deletionPolicy: "Delete" + managementPolicies: ["*"] providerConfigName: "default" version: "1.32" nodes = { @@ -426,10 +417,6 @@ _items = [ instanceType: "t3.small" } } - writeConnectionSecretToRef = { - name: "platform-ref-aws-eks" - namespace: "crossplane-system" - } } status = { conditions = [ @@ -445,18 +432,18 @@ _items = [ } } }, - # XAWSLBController with Ready condition to trigger Flux and OSS creation - awsplatformv1alpha1.XAWSLBController{ + # AWSLBController with Ready condition to trigger Flux and OSS creation + awsplatformv1alpha1.AWSLBController{ metadata = { name: "platform-ref-aws-lb-controller" annotations = { - "crossplane.io/composition-resource-name" = "XAWSLBController" + "crossplane.io/composition-resource-name" = "AWSLBController" } } spec = { parameters = { providerConfigName: "default" - deletionPolicy: "Delete" + managementPolicies: ["*"] helm = { providerConfigName: "platform-ref-aws" } @@ -481,9 +468,9 @@ _items = [ } } ] - compositionPath: "apis/composition.yaml" - xrPath: "examples/xcluster.yaml" - xrdPath: "apis/definition.yaml" + compositionPath: "apis/clusters/composition.yaml" + xrPath: "examples/cluster/cluster.yaml" + xrdPath: "apis/clusters/definition.yaml" timeoutSeconds: 120 validate: False } diff --git a/upbound.yaml b/upbound.yaml index 5cc8a75..c4a32bd 100644 --- a/upbound.yaml +++ b/upbound.yaml @@ -1,37 +1,46 @@ -apiVersion: meta.dev.upbound.io/v1alpha1 +apiVersion: meta.dev.upbound.io/v2alpha1 kind: Project metadata: name: platform-ref-aws spec: + apiDependencies: + - k8s: + version: v1.33.0 + type: k8s + - git: + path: cluster/crds + ref: release-2.1 + repository: https://github.com/crossplane/crossplane + type: crd dependsOn: - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-aws-lb-controller - version: v0.5.0 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-aws-network - version: v0.24.0 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-aws-database - version: v0.16.0 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-aws-eks - version: v0.19.0 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-app - version: v0.12.1 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-observability-oss - version: v0.10.1 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Configuration package: xpkg.upbound.io/upbound/configuration-gitops-flux - version: v0.12.0 + version: v2.0.0 - apiVersion: pkg.crossplane.io/v1 kind: Function package: xpkg.upbound.io/crossplane-contrib/function-auto-ready