diff --git a/examples/clusterclasses/aws/eks/clusterclass-eks-example.yaml b/examples/clusterclasses/aws/eks/clusterclass-eks-example.yaml new file mode 100644 index 000000000..f0c089753 --- /dev/null +++ b/examples/clusterclasses/aws/eks/clusterclass-eks-example.yaml @@ -0,0 +1,154 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + name: aws-eks-example +spec: + controlPlane: + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta2 + kind: AWSManagedControlPlaneTemplate + name: "eks-control-plane" + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSManagedClusterTemplate + name: "eks-cluster" + workers: + machineDeployments: + - class: default-worker + template: + bootstrap: + ref: + name: "eks-md-0" + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: EKSConfigTemplate + infrastructure: + ref: + name: "eks-md-0" + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSMachineTemplate + variables: + - name: region + required: true + schema: + openAPIV3Schema: + description: "The AWS region where the Cluster will be created" + type: string + - name: sshKeyName + required: false + schema: + openAPIV3Schema: + description: "AWS SSH key name to use" + type: string + default: '' + - name: instanceType + required: false + schema: + openAPIV3Schema: + description: "AWS instance type to use" + type: string + default: "t3.xlarge" + - name: eksClusterName + required: false + schema: + openAPIV3Schema: + description: "EKS cluster name" + type: string + default: '' + - name: awsClusterIdentityName + required: true + schema: + openAPIV3Schema: + description: The AWSClusterStaticIdentity resource name referencing the credentials to create the Cluster. + type: string + default: cluster-identity + patches: + - name: awsManagedControlPlaneTemplate + definitions: + - selector: + apiVersion: controlplane.cluster.x-k8s.io/v1beta2 + kind: AWSManagedControlPlaneTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: add + enabledIf: '{{ ne .eksClusterName }}' + path: /spec/template/spec/eksClusterName + valueFrom: + variable: eksClusterName + - op: add + path: /spec/template/spec/region + valueFrom: + variable: region + - op: add + enabledIf: '{{ ne .sshKeyName }}' + path: /spec/template/spec/sshKeyName + valueFrom: + variable: sshKeyName + - op: add + path: /spec/template/spec/identityRef/name + valueFrom: + variable: awsClusterIdentityName + # Builtins + - op: add + path: "/spec/template/spec/version" + valueFrom: + variable: builtin.cluster.topology.version + - name: awsMachineTemplate + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: add + enabledIf: '{{ ne .sshKeyName }}' + path: /spec/template/spec/sshKeyName + valueFrom: + variable: sshKeyName + - op: add + path: /spec/template/spec/instanceType + valueFrom: + variable: instanceType +--- +kind: AWSManagedClusterTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +metadata: + name: "eks-cluster" +spec: + template: + spec: {} +--- +kind: AWSManagedControlPlaneTemplate +apiVersion: controlplane.cluster.x-k8s.io/v1beta2 +metadata: + name: "eks-control-plane" +spec: + template: + spec: + region: "replaced_by_patch" + version: "v0.0.0" # To be replaced by patch + identityRef: + kind: AWSClusterStaticIdentity + name: cluster-identity +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSMachineTemplate +metadata: + name: "eks-md-0" +spec: + template: + spec: + instanceType: "replaced_by_patch" + iamInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io" +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 +kind: EKSConfigTemplate +metadata: + name: "eks-md-0" +spec: + template: + spec: {} diff --git a/test/e2e/const.go b/test/e2e/const.go index da805d104..e6e57c235 100644 --- a/test/e2e/const.go +++ b/test/e2e/const.go @@ -87,8 +87,8 @@ var ( //go:embed data/cluster-templates/docker-rke2-topology.yaml CAPIDockerRKE2Topology []byte - //go:embed data/cluster-templates/aws-eks-mmp.yaml - CAPIAwsEKSMMP []byte + //go:embed data/cluster-templates/aws-eks-topology.yaml + CAPIAwsEKSTopology []byte //go:embed data/cluster-templates/aws-ec2-rke2-topology.yaml CAPIAwsEC2RKE2Topology []byte diff --git a/test/e2e/data/cluster-templates/aws-eks-mmp.yaml b/test/e2e/data/cluster-templates/aws-eks-mmp.yaml deleted file mode 100644 index 04b96dc2c..000000000 --- a/test/e2e/data/cluster-templates/aws-eks-mmp.yaml +++ /dev/null @@ -1,77 +0,0 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 -kind: AWSClusterStaticIdentity -metadata: - name: cluster-identity -spec: - secretRef: cluster-identity - allowedNamespaces: {} ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: "${CLUSTER_NAME}" - namespace: "${NAMESPACE}" -spec: - clusterNetwork: - pods: - cidrBlocks: ["192.168.0.0/16"] - infrastructureRef: - kind: AWSManagedCluster - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - name: "${CLUSTER_NAME}" - controlPlaneRef: - kind: AWSManagedControlPlane - apiVersion: controlplane.cluster.x-k8s.io/v1beta2 - name: "${CLUSTER_NAME}-control-plane" ---- -kind: AWSManagedCluster -apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 -metadata: - name: "${CLUSTER_NAME}" - namespace: "${NAMESPACE}" - annotations: - "helm.sh/resource-policy": keep -spec: {} ---- -kind: AWSManagedControlPlane -apiVersion: controlplane.cluster.x-k8s.io/v1beta2 -metadata: - name: "${CLUSTER_NAME}-control-plane" - namespace: "${NAMESPACE}" - annotations: - "helm.sh/resource-policy": keep -spec: - region: "eu-west-2" - version: "${KUBERNETES_VERSION}" - identityRef: - name: cluster-identity - kind: AWSClusterStaticIdentity ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachinePool -metadata: - name: "${CLUSTER_NAME}-pool-0" - namespace: "${NAMESPACE}" - annotations: - "helm.sh/resource-policy": keep -spec: - clusterName: "${CLUSTER_NAME}" - replicas: ${WORKER_MACHINE_COUNT} - template: - spec: - clusterName: "${CLUSTER_NAME}" - bootstrap: - dataSecretName: "" - infrastructureRef: - name: "${CLUSTER_NAME}-pool-0" - apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 - kind: AWSManagedMachinePool ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 -kind: AWSManagedMachinePool -metadata: - name: "${CLUSTER_NAME}-pool-0" - namespace: "${NAMESPACE}" - annotations: - "helm.sh/resource-policy": keep -spec: {} diff --git a/test/e2e/data/cluster-templates/aws-eks-topology.yaml b/test/e2e/data/cluster-templates/aws-eks-topology.yaml new file mode 100644 index 000000000..461a79556 --- /dev/null +++ b/test/e2e/data/cluster-templates/aws-eks-topology.yaml @@ -0,0 +1,38 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSClusterStaticIdentity +metadata: + name: cluster-identity +spec: + secretRef: cluster-identity + allowedNamespaces: {} +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} + namespace: "${NAMESPACE}" + labels: + cluster-api.cattle.io/rancher-auto-import: "true" +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.0.0/16 + topology: + class: aws-eks-example + classNamespace: ${TOPOLOGY_NAMESPACE} + version: ${AWS_KUBERNETES_VERSION} + variables: + - name: region + value: ${AWS_REGION} + - name: sshKeyName + value: ${AWS_SSH_KEY_NAME} + - name: instanceType + value: t3.xlarge + - name: awsClusterIdentityName + value: cluster-identity + workers: + machineDeployments: + - class: default-worker + name: md-0 + replicas: ${WORKER_MACHINE_COUNT} diff --git a/test/e2e/suites/import-gitops/import_gitops_test.go b/test/e2e/suites/import-gitops/import_gitops_test.go index 16410cb9b..108888ae1 100644 --- a/test/e2e/suites/import-gitops/import_gitops_test.go +++ b/test/e2e/suites/import-gitops/import_gitops_test.go @@ -261,17 +261,21 @@ var _ = Describe("[Azure] [RKE2] Create and delete CAPI cluster from cluster cla }) }) -var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster functionality should work with namespace auto-import", Label(e2e.FullTestLabel), func() { +var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster from cluster class", Label(e2e.FullTestLabel), func() { + var topologyNamespace string + BeforeEach(func() { komega.SetClient(bootstrapClusterProxy.GetClient()) komega.SetContext(ctx) + + topologyNamespace = "creategitops-aws-eks" }) specs.CreateUsingGitOpsSpec(ctx, func() specs.CreateUsingGitOpsSpecInput { return specs.CreateUsingGitOpsSpecInput{ E2EConfig: e2e.LoadE2EConfig(), BootstrapClusterProxy: bootstrapClusterProxy, - ClusterTemplate: e2e.CAPIAwsEKSMMP, + ClusterTemplate: e2e.CAPIAwsEKSTopology, ClusterName: "cluster-eks", ControlPlaneMachineCount: ptr.To(1), WorkerMachineCount: ptr.To(1), @@ -282,6 +286,18 @@ var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster functionality shoul CapiClusterOwnerLabel: e2e.CapiClusterOwnerLabel, CapiClusterOwnerNamespaceLabel: e2e.CapiClusterOwnerNamespaceLabel, OwnedLabelName: e2e.OwnedLabelName, + TopologyNamespace: topologyNamespace, + AdditionalTemplateVariables: map[string]string{ + e2e.KubernetesVersionVar: e2e.LoadE2EConfig().GetVariableOrEmpty(e2e.AWSKubernetesVersionVar), // override the default k8s version + }, + AdditionalFleetGitRepos: []turtlesframework.FleetCreateGitRepoInput{ + { + Name: "aws-cluster-classes-eks", + Paths: []string{"examples/clusterclasses/aws/eks"}, + ClusterProxy: bootstrapClusterProxy, + TargetNamespace: topologyNamespace, + }, + }, } }) })