diff --git a/test/e2e/config/gcp-ci.yaml b/test/e2e/config/gcp-ci.yaml index d14a5d9ee..86751cfb9 100644 --- a/test/e2e/config/gcp-ci.yaml +++ b/test/e2e/config/gcp-ci.yaml @@ -66,7 +66,7 @@ providers: - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-upgrades.yaml" - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-md-remediation.yaml" - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-kcp-remediation.yaml" - - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-topology.yaml" + - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/withclusterclass/cluster-template-ci-topology.yaml" - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/clusterclass-quick-start.yaml" - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-with-creds.yaml" - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml" diff --git a/test/e2e/data/infrastructure-gcp/cluster-template-topology.yaml b/test/e2e/data/infrastructure-gcp/cluster-template-topology.yaml deleted file mode 100644 index 5f7cdaa3d..000000000 --- a/test/e2e/data/infrastructure-gcp/cluster-template-topology.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: "${CLUSTER_NAME}" - labels: - cni: "${CLUSTER_NAME}-crs-cni" -spec: - clusterNetwork: - pods: - cidrBlocks: ["192.168.0.0/16"] - topology: - class: quick-start - version: "${KUBERNETES_VERSION}" - controlPlane: - replicas: ${CONTROL_PLANE_MACHINE_COUNT} - workers: - machineDeployments: - - class: "default-worker" - name: "md-0" - replicas: ${WORKER_MACHINE_COUNT} - variables: - - name: region - value: ${GCP_REGION} - - name: controlPlaneMachineType - value: ${GCP_CONTROL_PLANE_MACHINE_TYPE} - - name: workerMachineType - value: ${GCP_NODE_MACHINE_TYPE} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: "${CLUSTER_NAME}-crs-cni" -data: ${CNI_RESOURCES} ---- -apiVersion: addons.cluster.x-k8s.io/v1beta1 -kind: ClusterResourceSet -metadata: - name: "${CLUSTER_NAME}-crs-cni" -spec: - strategy: ApplyOnce - clusterSelector: - matchLabels: - cni: "${CLUSTER_NAME}-crs-cni" - resources: - - name: "${CLUSTER_NAME}-crs-cni" - kind: ConfigMap diff --git a/test/e2e/data/infrastructure-gcp/withclusterclass/cluster-template-ci-topology.yaml b/test/e2e/data/infrastructure-gcp/withclusterclass/cluster-template-ci-topology.yaml new file mode 100644 index 000000000..31c797f59 --- /dev/null +++ b/test/e2e/data/infrastructure-gcp/withclusterclass/cluster-template-ci-topology.yaml @@ -0,0 +1,214 @@ +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + name: quick-start +spec: + controlPlane: + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + name: quick-start-control-plane + machineInfrastructure: + ref: + kind: GCPMachineTemplate + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + name: quick-start-control-plane + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPClusterTemplate + name: quick-start + workers: + machineDeployments: + - class: default-worker + template: + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: quick-start-worker-bootstraptemplate + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPMachineTemplate + name: quick-start-worker-machinetemplate + variables: + - name: region + required: true + schema: + openAPIV3Schema: + type: string + default: us-west1 + - name: controlPlaneMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: n1-standard-2 + - name: workerMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: n1-standard-2 + patches: + - name: region + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPClusterTemplate + matchResources: + infrastructureCluster: true + jsonPatches: + - op: add + path: /spec/template/spec/region + valueFrom: + variable: region + - name: controlPlaneMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/instanceType + valueFrom: + variable: controlPlaneMachineType + - name: workerMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/instanceType + valueFrom: + variable: workerMachineType +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPClusterTemplate +metadata: + name: quick-start +spec: + template: + spec: + project: "${GCP_PROJECT}" + region: "${GCP_REGION}" + network: + name: "${GCP_NETWORK_NAME}" +--- +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +kind: KubeadmControlPlaneTemplate +metadata: + name: quick-start-control-plane +spec: + template: + spec: + kubeadmConfigSpec: + useExperimentalRetryJoin: true + initConfiguration: + nodeRegistration: + name: '{{ ds.meta_data.local_hostname.split(".")[0] }}' + kubeletExtraArgs: + cloud-provider: gce + clusterConfiguration: + apiServer: + timeoutForControlPlane: 20m + extraArgs: + cloud-provider: gce + controllerManager: + extraArgs: + cloud-provider: gce + allocate-node-cidrs: "false" + joinConfiguration: + nodeRegistration: + name: '{{ ds.meta_data.local_hostname.split(".")[0] }}' + kubeletExtraArgs: + cloud-provider: gce +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPMachineTemplate +metadata: + name: quick-start-control-plane +spec: + template: + spec: + instanceType: REPLACEME + image: "${IMAGE_ID}" +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPMachineTemplate +metadata: + name: quick-start-worker-machinetemplate +spec: + template: + spec: + instanceType: REPLACEME + image: "${IMAGE_ID}" +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: quick-start-worker-bootstraptemplate +spec: + template: + spec: + joinConfiguration: + nodeRegistration: + name: '{{ ds.meta_data.local_hostname.split(".")[0] }}' + kubeletExtraArgs: + cloud-provider: gce +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: "${CLUSTER_NAME}" + labels: + cni: "${CLUSTER_NAME}-crs-cni" +spec: + clusterNetwork: + pods: + cidrBlocks: ["192.168.0.0/16"] + topology: + class: quick-start + version: "${KUBERNETES_VERSION}" + controlPlane: + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + workers: + machineDeployments: + - class: "default-worker" + name: "md-0" + replicas: ${WORKER_MACHINE_COUNT} + variables: + - name: region + value: ${GCP_REGION} + - name: controlPlaneMachineType + value: ${GCP_CONTROL_PLANE_MACHINE_TYPE} + - name: workerMachineType + value: ${GCP_NODE_MACHINE_TYPE} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: "${CLUSTER_NAME}-crs-cni" +data: ${CNI_RESOURCES} +--- +apiVersion: addons.cluster.x-k8s.io/v1beta1 +kind: ClusterResourceSet +metadata: + name: "${CLUSTER_NAME}-crs-cni" +spec: + strategy: ApplyOnce + clusterSelector: + matchLabels: + cni: "${CLUSTER_NAME}-crs-cni" + resources: + - name: "${CLUSTER_NAME}-crs-cni" + kind: ConfigMap diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 906ae0698..028ac26c0 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -206,4 +206,28 @@ var _ = Describe("Workload cluster creation", func() { }, result) }) }) + + Context("Creating a cluster using a cluster class", func() { + It("Should create a cluster class and then a cluster based on it", func() { + By("Creating a cluster from a topology") + clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ + ClusterProxy: bootstrapClusterProxy, + ConfigCluster: clusterctl.ConfigClusterInput{ + LogFolder: clusterctlLogFolder, + ClusterctlConfigPath: clusterctlConfigPath, + KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(), + InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, + Flavor: "ci-topology", + Namespace: namespace.Name, + ClusterName: clusterName, + KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion), + ControlPlaneMachineCount: ptr.To[int64](1), + WorkerMachineCount: ptr.To[int64](1), + }, + WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"), + WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"), + WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"), + }, result) + }) + }) })