From 9d5e2cd0c30fc4cb7e52c49f9ef14a4f80dfd9ff Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Mon, 17 Mar 2025 14:20:36 +0100 Subject: [PATCH 1/6] run gke e2e on pr ci Signed-off-by: Carlos Salas --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c5136e200..d980266f0 100644 --- a/Makefile +++ b/Makefile @@ -167,7 +167,7 @@ test: $(SETUP_ENVTEST) ## Run unit and integration tests KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS) # Allow overriding the e2e configurations -GINKGO_FOCUS ?= Workload cluster creation +GINKGO_FOCUS ?= Workload cluster creation|GKE workload cluster creation GINKGO_SKIP ?= API Version Upgrade GINKGO_NODES ?= 1 GINKGO_NOCOLOR ?= false From e2e5517e3f803d0ad062a007f91bd1af6d564ef4 Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Tue, 27 May 2025 09:43:58 +0200 Subject: [PATCH 2/6] test: use unique gke cluster name to prevent collisions Signed-off-by: Carlos Salas --- test/e2e/e2e_gke_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/e2e/e2e_gke_test.go b/test/e2e/e2e_gke_test.go index 86507ab41..946648f55 100644 --- a/test/e2e/e2e_gke_test.go +++ b/test/e2e/e2e_gke_test.go @@ -45,7 +45,7 @@ var _ = Describe("GKE workload cluster creation", func() { namespace *corev1.Namespace cancelWatches context.CancelFunc result *ApplyManagedClusterTemplateAndWaitResult - clusterName string + clusterNamePrefix string clusterctlLogFolder string ) @@ -57,7 +57,7 @@ var _ = Describe("GKE workload cluster creation", func() { Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) - clusterName = fmt.Sprintf("capg-e2e-%s", util.RandomString(6)) + clusterNamePrefix = fmt.Sprintf("capg-e2e-gke-%s", util.RandomString(6)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. namespace, cancelWatches = setupSpecNamespace(ctx, specName, bootstrapClusterProxy, artifactFolder) @@ -86,6 +86,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster without autopilot", func() { It("Should create a cluster with 1 machine pool and scale", func() { + clusterName := fmt.Sprintf("%s-single", clusterNamePrefix) By("Initializes with 1 machine pool") minPoolSize, ok := e2eConfig.Variables["GKE_MACHINE_POOL_MIN"] @@ -144,6 +145,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster with autopilot", func() { It("Should create a cluster with 1 machine pool and scale", func() { + clusterName := fmt.Sprintf("%s-autopilot", clusterNamePrefix) By("Initializes with 1 machine pool") ApplyManagedClusterTemplateAndWait(ctx, ApplyManagedClusterTemplateAndWaitInput{ @@ -169,6 +171,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster with custom subnet", func() { It("Should create a cluster with 3 machine pool and custom subnet", func() { + clusterName := fmt.Sprintf("%s-custom-subnet", clusterNamePrefix) By("Initializes with 3 machine pool") ApplyManagedClusterTemplateAndWait(ctx, ApplyManagedClusterTemplateAndWaitInput{ From 7ce8568d19997217a0ed278bf67296a61719e990 Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Mon, 7 Jul 2025 12:35:02 +0200 Subject: [PATCH 3/6] set gke-specific k8s version in e2e Signed-off-by: Carlos Salas --- test/e2e/config/gcp-ci.yaml | 1 + test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml | 2 +- .../infrastructure-gcp/cluster-template-kcp-remediation.yaml | 2 +- test/e2e/e2e_gke_test.go | 2 +- test/e2e/suite_test.go | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/e2e/config/gcp-ci.yaml b/test/e2e/config/gcp-ci.yaml index 6ad0bda77..df82a078f 100644 --- a/test/e2e/config/gcp-ci.yaml +++ b/test/e2e/config/gcp-ci.yaml @@ -80,6 +80,7 @@ providers: variables: KUBERNETES_VERSION: "v1.32.5" KUBERNETES_VERSION_MANAGEMENT: "v1.32.5" + KUBERNETES_VERSION_GKE: "v1.32.4" ETCD_VERSION_UPGRADE_TO: "3.5.16-0" COREDNS_VERSION_UPGRADE_TO: "v1.11.3" KUBERNETES_IMAGE_UPGRADE_FROM: "projects/k8s-staging-cluster-api-gcp/global/images/cluster-api-ubuntu-2204-v1-32-5-nightly" diff --git a/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml b/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml index e1e40c160..63bdedfc8 100644 --- a/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml +++ b/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml @@ -33,7 +33,7 @@ metadata: spec: project: "${GCP_PROJECT}" location: "${GCP_REGION}" - version: "${KUBERNETES_VERSION}" + version: "${KUBERNETES_VERSION_GKE}" releaseChannel: "regular" --- apiVersion: cluster.x-k8s.io/v1beta1 diff --git a/test/e2e/data/infrastructure-gcp/cluster-template-kcp-remediation.yaml b/test/e2e/data/infrastructure-gcp/cluster-template-kcp-remediation.yaml index 1e2d03a92..ea2923113 100644 --- a/test/e2e/data/infrastructure-gcp/cluster-template-kcp-remediation.yaml +++ b/test/e2e/data/infrastructure-gcp/cluster-template-kcp-remediation.yaml @@ -54,7 +54,7 @@ spec: extraArgs: cloud-provider: external allocate-node-cidrs: "false" - kubernetesVersion: "${KUBERNETES_VERSION}" + kubernetesVersion: "${KUBERNETES_VERSION_GKE}" files: - content: | [Global] diff --git a/test/e2e/e2e_gke_test.go b/test/e2e/e2e_gke_test.go index 946648f55..3ea900e22 100644 --- a/test/e2e/e2e_gke_test.go +++ b/test/e2e/e2e_gke_test.go @@ -108,7 +108,7 @@ var _ = Describe("GKE workload cluster creation", func() { Flavor: "ci-gke", Namespace: namespace.Name, ClusterName: clusterName, - KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion), + KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersionGKE), ControlPlaneMachineCount: ptr.To[int64](1), WorkerMachineCount: ptr.To[int64](3), ClusterctlVariables: map[string]string{ diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index a205785d5..0895885b7 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -45,6 +45,7 @@ import ( const ( KubernetesVersion = "KUBERNETES_VERSION" KubernetesVersionManagement = "KUBERNETES_VERSION_MANAGEMENT" + KubernetesVersionGKE = "KUBERNETES_VERSION_GKE" CNIPath = "CNI" CNIResources = "CNI_RESOURCES" From c99ca954a62698e84b27f9da9d2d3afa467eb92c Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Wed, 27 Aug 2025 10:40:05 +0200 Subject: [PATCH 4/6] test: add missing cluster name in e2e test case and truncate length Signed-off-by: Carlos Salas --- test/e2e/e2e_gke_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/e2e/e2e_gke_test.go b/test/e2e/e2e_gke_test.go index 3ea900e22..3d32cd0b4 100644 --- a/test/e2e/e2e_gke_test.go +++ b/test/e2e/e2e_gke_test.go @@ -41,7 +41,7 @@ const ( var _ = Describe("GKE workload cluster creation", func() { var ( ctx = context.TODO() - specName = "create-gke-workload-cluster" + specName = "gke" namespace *corev1.Namespace cancelWatches context.CancelFunc result *ApplyManagedClusterTemplateAndWaitResult @@ -57,7 +57,7 @@ var _ = Describe("GKE workload cluster creation", func() { Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) - clusterNamePrefix = fmt.Sprintf("capg-e2e-gke-%s", util.RandomString(6)) + clusterNamePrefix = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. namespace, cancelWatches = setupSpecNamespace(ctx, specName, bootstrapClusterProxy, artifactFolder) @@ -145,7 +145,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster with autopilot", func() { It("Should create a cluster with 1 machine pool and scale", func() { - clusterName := fmt.Sprintf("%s-autopilot", clusterNamePrefix) + clusterName := fmt.Sprintf("%s-ap", clusterNamePrefix) By("Initializes with 1 machine pool") ApplyManagedClusterTemplateAndWait(ctx, ApplyManagedClusterTemplateAndWaitInput{ @@ -171,7 +171,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster with custom subnet", func() { It("Should create a cluster with 3 machine pool and custom subnet", func() { - clusterName := fmt.Sprintf("%s-custom-subnet", clusterNamePrefix) + clusterName := fmt.Sprintf("%s-cust-snet", clusterNamePrefix) By("Initializes with 3 machine pool") ApplyManagedClusterTemplateAndWait(ctx, ApplyManagedClusterTemplateAndWaitInput{ @@ -201,6 +201,7 @@ var _ = Describe("GKE workload cluster creation", func() { Context("Creating a GKE cluster with autopilot from a cluster class", func() { It("Should create a cluster class and a cluster from it", func() { + clusterName := fmt.Sprintf("%s-cc", clusterNamePrefix) By("Initializes a managed control plane and managed cluster") ApplyManagedClusterTemplateAndWait(ctx, ApplyManagedClusterTemplateAndWaitInput{ From 634488109e6d5cd30118c667bfd6a498879dd81d Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Wed, 27 Aug 2025 17:54:23 +0200 Subject: [PATCH 5/6] test: bump e2e gke k8s version to v1.32.5 Signed-off-by: Carlos Salas --- test/e2e/config/gcp-ci.yaml | 2 +- test/e2e/e2e_gke_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/config/gcp-ci.yaml b/test/e2e/config/gcp-ci.yaml index df82a078f..06a8a8641 100644 --- a/test/e2e/config/gcp-ci.yaml +++ b/test/e2e/config/gcp-ci.yaml @@ -80,7 +80,7 @@ providers: variables: KUBERNETES_VERSION: "v1.32.5" KUBERNETES_VERSION_MANAGEMENT: "v1.32.5" - KUBERNETES_VERSION_GKE: "v1.32.4" + KUBERNETES_VERSION_GKE: "v1.32.6" ETCD_VERSION_UPGRADE_TO: "3.5.16-0" COREDNS_VERSION_UPGRADE_TO: "v1.11.3" KUBERNETES_IMAGE_UPGRADE_FROM: "projects/k8s-staging-cluster-api-gcp/global/images/cluster-api-ubuntu-2204-v1-32-5-nightly" diff --git a/test/e2e/e2e_gke_test.go b/test/e2e/e2e_gke_test.go index 3d32cd0b4..c18987fdb 100644 --- a/test/e2e/e2e_gke_test.go +++ b/test/e2e/e2e_gke_test.go @@ -55,7 +55,7 @@ var _ = Describe("GKE workload cluster creation", func() { Expect(bootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName) Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) - Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) + Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersionGKE)) clusterNamePrefix = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) @@ -158,7 +158,7 @@ var _ = Describe("GKE workload cluster creation", func() { Flavor: "ci-gke-autopilot", Namespace: namespace.Name, ClusterName: clusterName, - KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion), + KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersionGKE), ControlPlaneMachineCount: ptr.To[int64](1), WorkerMachineCount: ptr.To[int64](0), }, @@ -184,7 +184,7 @@ var _ = Describe("GKE workload cluster creation", func() { Flavor: "ci-gke-custom-subnet", Namespace: namespace.Name, ClusterName: clusterName, - KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion), + KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersionGKE), ControlPlaneMachineCount: ptr.To[int64](1), WorkerMachineCount: ptr.To[int64](3), ClusterctlVariables: map[string]string{ @@ -214,7 +214,7 @@ var _ = Describe("GKE workload cluster creation", func() { Flavor: "ci-gke-autopilot-topology", Namespace: namespace.Name, ClusterName: clusterName, - KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion), + KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersionGKE), ControlPlaneMachineCount: ptr.To[int64](1), WorkerMachineCount: ptr.To[int64](0), }, From 5d597f69451a3f6e49b932b3a8ce1e66addeb841 Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Thu, 28 Aug 2025 08:49:40 +0200 Subject: [PATCH 6/6] test: add debug log to print service account Signed-off-by: Carlos Salas --- cloud/services/container/clusters/kubeconfig.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cloud/services/container/clusters/kubeconfig.go b/cloud/services/container/clusters/kubeconfig.go index 978ead85c..62923a2f1 100644 --- a/cloud/services/container/clusters/kubeconfig.go +++ b/cloud/services/container/clusters/kubeconfig.go @@ -34,6 +34,7 @@ import ( infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/kubeconfig" "sigs.k8s.io/cluster-api/util/secret" + "sigs.k8s.io/controller-runtime/pkg/log" ) const ( @@ -238,12 +239,14 @@ func (s *Service) createBaseKubeConfig(contextName string, cluster *containerpb. } func (s *Service) generateToken(ctx context.Context) (string, error) { + log := log.FromContext(ctx) req := &credentialspb.GenerateAccessTokenRequest{ Name: "projects/-/serviceAccounts/" + s.scope.GetCredential().ClientEmail, Scope: []string{ GkeScope, }, } + log.Info("DEBUG - Generating Token", "serviceAccount", req.Name, "scopes", req.Scope) resp, err := s.scope.CredentialsClient().GenerateAccessToken(ctx, req) if err != nil { return "", errors.Errorf("error generating access token: %v", err)