Skip to content

Commit

Permalink
tests: Ensure all dnsrecords are removed in cleanup
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mikenairn committed Oct 15, 2024
1 parent d11ed02 commit 1744472
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
23 changes: 16 additions & 7 deletions tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
24 changes: 17 additions & 7 deletions tests/common/dnspolicy/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 1744472

Please sign in to comment.