From 2e6a5c9ffb80ee4dc95f6d07b73150682eb67bf6 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Thu, 11 Jun 2026 17:31:56 +0200 Subject: [PATCH] OCPBUGS-88037: Add e2e test verifying CAPI GCP instance ownership label Verify that the GCPCluster has the kubernetes-io-cluster-=owned label in AdditionalLabels, which CAPI propagates to all managed resources. The installer's destroy logic uses this label to find and clean up CAPI-created GCP resources. Signed-off-by: Matthias Wessendorf --- e2e/gcp_helpers.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ e2e/gcp_test.go | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 e2e/gcp_helpers.go diff --git a/e2e/gcp_helpers.go b/e2e/gcp_helpers.go new file mode 100644 index 0000000000..062f42af9d --- /dev/null +++ b/e2e/gcp_helpers.go @@ -0,0 +1,45 @@ +// Copyright 2026 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "fmt" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/openshift/cluster-capi-operator/e2e/framework" + "k8s.io/apimachinery/pkg/types" + gcpv1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1" +) + +// verifyCAPIInstanceOwnershipLabel asserts that the GCPCluster has the +// kubernetes-io-cluster-=owned label that openshift-install destroy cluster +// relies on to identify and clean up cloud resources. +func verifyCAPIInstanceOwnershipLabel(infraName string) { + GinkgoHelper() + By("Verifying GCPCluster has cluster ownership label") + + Expect(infraName).ToNot(BeEmpty()) + + gcpCluster := &gcpv1.GCPCluster{} + key := types.NamespacedName{Name: infraName, Namespace: framework.CAPINamespace} + Expect(cl.Get(ctx, key, gcpCluster)).To(Succeed(), "should be able to get GCPCluster %s", infraName) + + expectedLabelKey := fmt.Sprintf("kubernetes-io-cluster-%s", infraName) + Expect(gcpCluster.Spec.AdditionalLabels).ToNot(BeNil(), + "expected GCPCluster to have AdditionalLabels set") + Expect(gcpCluster.Spec.AdditionalLabels).To(HaveKeyWithValue(expectedLabelKey, "owned"), + "expected GCPCluster to have label %s=owned for cluster destroy to find CAPI-created resources", expectedLabelKey) +} diff --git a/e2e/gcp_test.go b/e2e/gcp_test.go index 3e72ab58fe..57f81531d4 100644 --- a/e2e/gcp_test.go +++ b/e2e/gcp_test.go @@ -75,6 +75,8 @@ var _ = Describe("Cluster API GCP MachineSet", Ordered, func() { )) framework.WaitForMachineSet(ctx, cl, machineSet.Name, machineSet.Namespace, framework.WaitLong) + + verifyCAPIInstanceOwnershipLabel(clusterName) }) })