Skip to content

Commit eaf2b33

Browse files
committed
OCPBUGS-88035: Add e2e test verifying CAPI EC2 instance ownership tag
Verify that a CAPI-created EC2 instance has the kubernetes.io/cluster/<infraID>=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 <mwessend@redhat.com>
1 parent 05c113e commit eaf2b33

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

e2e/aws_helpers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,26 @@ func compareInstances(awsClient *ec2.EC2, mapiMsName, capiMsName string) {
214214
}
215215
}
216216

217+
// verifyCAPIInstanceOwnershipTag asserts that a CAPI-created EC2 instance has the
218+
// kubernetes.io/cluster/<infraName>=owned tag that openshift-install destroy cluster
219+
// relies on to identify and clean up cloud resources.
220+
func verifyCAPIInstanceOwnershipTag(awsClient *ec2.EC2, capiMsName, infraName string) {
221+
GinkgoHelper()
222+
By("Verifying CAPI-created EC2 instance has cluster ownership tag")
223+
224+
Expect(awsClient).ToNot(BeNil())
225+
Expect(capiMsName).ToNot(BeEmpty())
226+
Expect(infraName).ToNot(BeEmpty())
227+
228+
instance := getCAPICreatedInstance(awsClient, capiMsName)
229+
230+
expectedTagKey := fmt.Sprintf("kubernetes.io/cluster/%s", infraName)
231+
Expect(instance.Tags).To(ContainElement(SatisfyAll(
232+
HaveField("Key", HaveValue(Equal(expectedTagKey))),
233+
HaveField("Value", HaveValue(Equal("owned"))),
234+
)), "expected EC2 instance to have tag %s=owned for cluster destroy to find it", expectedTagKey)
235+
}
236+
217237
// deleteAWSMachineTemplates deletes the specified AWSMachineTemplates.
218238
func deleteAWSMachineTemplates(ctx context.Context, cl client.Client, templates ...*awsv1.AWSMachineTemplate) {
219239
GinkgoHelper()

e2e/aws_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
7979
framework.WaitForMachineSet(ctx, cl, machineSet.Name, machineSet.Namespace, framework.WaitLong)
8080

8181
compareInstances(awsClient, mapiDefaultMS.Name, "aws-machineset")
82+
verifyCAPIInstanceOwnershipTag(awsClient, "aws-machineset", clusterName)
8283
})
8384
})

0 commit comments

Comments
 (0)