From 49070ee1b41905b55bc26dc929c0b99663530d49 Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Thu, 7 Nov 2024 18:53:45 +0100 Subject: [PATCH] test: provision gke cluster in full e2e test Signed-off-by: Carlos Salas --- test/e2e/config/operator.yaml | 2 + test/e2e/const.go | 4 ++ test/e2e/data/cluster-templates/gcp-gke.yaml | 59 +++++++++++++++++++ test/e2e/specs/import_gitops_mgmtv3.go | 1 + .../import-gitops-v3/import_gitops_v3_test.go | 32 ++++++++++ 5 files changed, 98 insertions(+) create mode 100644 test/e2e/data/cluster-templates/gcp-gke.yaml diff --git a/test/e2e/config/operator.yaml b/test/e2e/config/operator.yaml index 8455bec2..20fdf318 100644 --- a/test/e2e/config/operator.yaml +++ b/test/e2e/config/operator.yaml @@ -12,6 +12,7 @@ intervals: default/wait-v2prov-create: ["25m", "30s"] default/wait-capa-create-cluster: ["30m", "30s"] default/wait-capz-create-cluster: ["35m", "30s"] + default/wait-capg-create-cluster: ["30m", "30s"] default/wait-capv-create-cluster: ["30m", "30s"] default/wait-gitea: ["3m", "10s"] default/wait-gitpush: ["3m", "10s"] @@ -19,6 +20,7 @@ intervals: default/wait-getservice: ["5m", "30s"] default/wait-eks-delete: ["35m", "30s"] default/wait-aks-delete: ["30m", "30s"] + default/wait-gke-delete: ["35m", "30s"] default/wait-azure-delete: ["15m", "30s"] default/wait-azure: ["30m", "30s"] default/wait-vsphere-delete: ["20m", "30s"] diff --git a/test/e2e/const.go b/test/e2e/const.go index 4837fb34..7fc04b53 100644 --- a/test/e2e/const.go +++ b/test/e2e/const.go @@ -81,6 +81,9 @@ var ( //go:embed data/cluster-templates/aws-eks-mmp.yaml CAPIAwsEKSMMP []byte + //go:embed data/cluster-templates/gcp-gke.yaml + CAPIGCPGKE []byte + //go:embed data/cluster-templates/azure-aks-topology.yaml CAPIAzureAKSTopology []byte @@ -162,6 +165,7 @@ const ( CapaEncodedCredentialsVar = "CAPA_ENCODED_CREDS" CapgEncodedCredentialsVar = "CAPG_ENCODED_CREDS" + GCPProjectVar = "GCP_PROJECT" AzureSubIDVar = "AZURE_SUBSCRIPTION_ID" AzureClientIDVar = "AZURE_CLIENT_ID" AzureClientSecretVar = "AZURE_CLIENT_SECRET" diff --git a/test/e2e/data/cluster-templates/gcp-gke.yaml b/test/e2e/data/cluster-templates/gcp-gke.yaml new file mode 100644 index 00000000..80685357 --- /dev/null +++ b/test/e2e/data/cluster-templates/gcp-gke.yaml @@ -0,0 +1,59 @@ +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: "${CLUSTER_NAME}" +spec: + clusterNetwork: + pods: + cidrBlocks: ["192.168.0.0/16"] + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPManagedCluster + name: "${CLUSTER_NAME}" + controlPlaneRef: + kind: GCPManagedControlPlane + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + name: "${CLUSTER_NAME}-control-plane" +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPManagedCluster +metadata: + name: "${CLUSTER_NAME}" +spec: + project: "${GCP_PROJECT}" + region: "europe-west2" + network: + name: "highlander-ci" +--- +kind: GCPManagedControlPlane +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +metadata: + name: "${CLUSTER_NAME}-control-plane" +spec: + project: "${GCP_PROJECT}" + location: "europe-west2" + controlPlaneVersion: "${KUBERNETES_VERSION}" +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachinePool +metadata: + name: "${CLUSTER_NAME}-mp-0" +spec: + clusterName: "${CLUSTER_NAME}" + replicas: 3 # regional cluster means we need to use a multiple of 3 + template: + spec: + bootstrap: + dataSecretName: "" + clusterName: "${CLUSTER_NAME}" + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: GCPManagedMachinePool + name: "${CLUSTER_NAME}-mp-0" +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPManagedMachinePool +metadata: + name: "${CLUSTER_NAME}-mp-0" +spec: {} diff --git a/test/e2e/specs/import_gitops_mgmtv3.go b/test/e2e/specs/import_gitops_mgmtv3.go index a12ead5a..1eb7d107 100644 --- a/test/e2e/specs/import_gitops_mgmtv3.go +++ b/test/e2e/specs/import_gitops_mgmtv3.go @@ -232,6 +232,7 @@ func CreateMgmtV3UsingGitOpsSpec(ctx context.Context, inputGetter func() CreateM "CLUSTER_CLASS_NAME": fmt.Sprintf("%s-class", input.ClusterName), "WORKER_MACHINE_COUNT": strconv.Itoa(workerMachineCount), "CONTROL_PLANE_MACHINE_COUNT": strconv.Itoa(controlPlaneMachineCount), + "GCP_PROJECT": input.E2EConfig.GetVariable(e2e.GCPProjectVar), } for k, v := range input.AdditionalTemplateVariables { additionalVars[k] = v diff --git a/test/e2e/suites/import-gitops-v3/import_gitops_v3_test.go b/test/e2e/suites/import-gitops-v3/import_gitops_v3_test.go index 4f7e5a92..dd6e89f5 100644 --- a/test/e2e/suites/import-gitops-v3/import_gitops_v3_test.go +++ b/test/e2e/suites/import-gitops-v3/import_gitops_v3_test.go @@ -157,3 +157,35 @@ var _ = Describe("[AWS] [EKS] - [management.cattle.io/v3] Create and delete CAPI } }) }) + +var _ = Describe("[GCP] [GKE] - [management.cattle.io/v3] Create and delete CAPI cluster functionality should work with namespace auto-import", Label(e2e.FullTestLabel), func() { + BeforeEach(func() { + komega.SetClient(setupClusterResult.BootstrapClusterProxy.GetClient()) + komega.SetContext(ctx) + }) + + specs.CreateMgmtV3UsingGitOpsSpec(ctx, func() specs.CreateMgmtV3UsingGitOpsSpecInput { + return specs.CreateMgmtV3UsingGitOpsSpecInput{ + E2EConfig: e2eConfig, + BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, + ClusterctlConfigPath: flagVals.ConfigPath, + ClusterctlBinaryPath: e2eConfig.GetVariable(e2e.ClusterctlBinaryPathVar), + ArtifactFolder: artifactsFolder, + ClusterTemplate: e2e.CAPIGCPGKE, + ClusterName: "clusterv3-gke", + ControlPlaneMachineCount: ptr.To[int](1), + WorkerMachineCount: ptr.To[int](1), + GitAddr: giteaResult.GitAddress, + GitAuthSecretName: e2e.AuthSecretName, + SkipCleanup: false, + SkipDeletionTest: false, + LabelNamespace: true, + RancherServerURL: hostName, + CAPIClusterCreateWaitName: "wait-capg-create-cluster", + DeleteClusterWaitName: "wait-gke-delete", + CapiClusterOwnerLabel: e2e.CapiClusterOwnerLabel, + CapiClusterOwnerNamespaceLabel: e2e.CapiClusterOwnerNamespaceLabel, + OwnedLabelName: e2e.OwnedLabelName, + } + }) +})