From 1744472ddbe4f4ff65a50c1156dbedfbec735751 Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Tue, 15 Oct 2024 17:11:33 +0100 Subject: [PATCH] tests: Ensure all dnsrecords are removed in cleanup Ensures all DNSrecord resources in the current spec test namespace are marked for deletion and removed before removing the secret. Signed-off-by: Michael Nairn --- ...nspolicy_controller_single_cluster_test.go | 23 ++++++++++++------ .../dnspolicy/dnspolicy_controller_test.go | 24 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go b/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go index 531d60862..a724fa61b 100644 --- a/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go +++ b/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go @@ -115,15 +115,24 @@ var _ = Describe("DNSPolicy Single Cluster", func() { if dnsPolicy != nil { err := k8sClient.Delete(ctx, dnsPolicy) Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - // Wait until dns records are finished deleting since it can't finish deleting without the DNS provider secret - Eventually(func(g Gomega) { - dnsRecords := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(dnsRecords.Items).To(HaveLen(0)) - }).WithContext(ctx).Should(Succeed()) + } + //Ensure all dns records in the test namespace are deleted + dnsRecords := &kuadrantdnsv1alpha1.DNSRecordList{} + err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) + Expect(err).ToNot(HaveOccurred()) + for _, record := range dnsRecords.Items { + err := k8sClient.Delete(ctx, &record, client.PropagationPolicy(metav1.DeletePropagationForeground)) + Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) } + + // Wait until dns records are finished deleting since it can't finish deleting without the DNS provider secret + Eventually(func(g Gomega) { + err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(dnsRecords.Items).To(HaveLen(0)) + }).WithContext(ctx).Should(Succeed()) + if dnsProviderSecret != nil { err := k8sClient.Delete(ctx, dnsProviderSecret) Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) diff --git a/tests/common/dnspolicy/dnspolicy_controller_test.go b/tests/common/dnspolicy/dnspolicy_controller_test.go index 8caf1e3f8..5c4bbeefc 100644 --- a/tests/common/dnspolicy/dnspolicy_controller_test.go +++ b/tests/common/dnspolicy/dnspolicy_controller_test.go @@ -59,14 +59,24 @@ var _ = Describe("DNSPolicy controller", func() { if dnsPolicy != nil { err := k8sClient.Delete(ctx, dnsPolicy) Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - // Wait until dns records are finished deleting since it can't finish deleting without the DNS provider secret - Eventually(func(g Gomega) { - dnsRecords := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(dnsRecords.Items).To(HaveLen(0)) - }).WithContext(ctx).Should(Succeed()) } + + //Ensure all dns records in the test namespace are deleted + dnsRecords := &kuadrantdnsv1alpha1.DNSRecordList{} + err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) + Expect(err).ToNot(HaveOccurred()) + for _, record := range dnsRecords.Items { + err := k8sClient.Delete(ctx, &record, client.PropagationPolicy(metav1.DeletePropagationForeground)) + Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) + } + + // Wait until dns records are finished deleting since it can't finish deleting without the DNS provider secret + Eventually(func(g Gomega) { + err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(dnsRecords.Items).To(HaveLen(0)) + }).WithContext(ctx).Should(Succeed()) + if dnsProviderSecret != nil { err := k8sClient.Delete(ctx, dnsProviderSecret) Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())