From eaf2b335dbf08db241374799990fcb372145c38c Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Thu, 11 Jun 2026 09:02:07 +0200 Subject: [PATCH] OCPBUGS-88035: Add e2e test verifying CAPI EC2 instance ownership tag Verify that a CAPI-created EC2 instance has the kubernetes.io/cluster/=owned tag that openshift-install destroy cluster relies on to identify and clean up cloud resources. CAPA may already add this tag automatically via its Build() + WithCloudProvider() tag pipeline. This test confirms whether the tag is present without any explicit AdditionalTags on the AWSCluster object. Signed-off-by: Matthias Wessendorf --- e2e/aws_helpers.go | 20 ++++++++++++++++++++ e2e/aws_test.go | 1 + 2 files changed, 21 insertions(+) diff --git a/e2e/aws_helpers.go b/e2e/aws_helpers.go index 709f3f233..37db468e5 100644 --- a/e2e/aws_helpers.go +++ b/e2e/aws_helpers.go @@ -214,6 +214,26 @@ func compareInstances(awsClient *ec2.EC2, mapiMsName, capiMsName string) { } } +// verifyCAPIInstanceOwnershipTag asserts that a CAPI-created EC2 instance has the +// kubernetes.io/cluster/=owned tag that openshift-install destroy cluster +// relies on to identify and clean up cloud resources. +func verifyCAPIInstanceOwnershipTag(awsClient *ec2.EC2, capiMsName, infraName string) { + GinkgoHelper() + By("Verifying CAPI-created EC2 instance has cluster ownership tag") + + Expect(awsClient).ToNot(BeNil()) + Expect(capiMsName).ToNot(BeEmpty()) + Expect(infraName).ToNot(BeEmpty()) + + instance := getCAPICreatedInstance(awsClient, capiMsName) + + expectedTagKey := fmt.Sprintf("kubernetes.io/cluster/%s", infraName) + Expect(instance.Tags).To(ContainElement(SatisfyAll( + HaveField("Key", HaveValue(Equal(expectedTagKey))), + HaveField("Value", HaveValue(Equal("owned"))), + )), "expected EC2 instance to have tag %s=owned for cluster destroy to find it", expectedTagKey) +} + // deleteAWSMachineTemplates deletes the specified AWSMachineTemplates. func deleteAWSMachineTemplates(ctx context.Context, cl client.Client, templates ...*awsv1.AWSMachineTemplate) { GinkgoHelper() diff --git a/e2e/aws_test.go b/e2e/aws_test.go index cc376d8cb..bf8d832a1 100644 --- a/e2e/aws_test.go +++ b/e2e/aws_test.go @@ -79,5 +79,6 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() { framework.WaitForMachineSet(ctx, cl, machineSet.Name, machineSet.Namespace, framework.WaitLong) compareInstances(awsClient, mapiDefaultMS.Name, "aws-machineset") + verifyCAPIInstanceOwnershipTag(awsClient, "aws-machineset", clusterName) }) })