From 54cb7ce515e3bbc31cc7526e553f144b7cfa7d53 Mon Sep 17 00:00:00 2001 From: Maskym Vavilov Date: Thu, 16 May 2024 16:18:14 +0100 Subject: [PATCH] elliminate premature termination of DNS controller logic --- ...nspolicy_controller_single_cluster_test.go | 23 +++++++++++++++++++ controllers/dnspolicy_dnsrecords.go | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/controllers/dnspolicy_controller_single_cluster_test.go b/controllers/dnspolicy_controller_single_cluster_test.go index d66db640c..0e14adee4 100644 --- a/controllers/dnspolicy_controller_single_cluster_test.go +++ b/controllers/dnspolicy_controller_single_cluster_test.go @@ -20,6 +20,7 @@ import ( "github.com/kuadrant/kuadrant-operator/api/v1alpha1" "github.com/kuadrant/kuadrant-operator/pkg/common" + "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" ) @@ -48,6 +49,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() { Expect(k8sClient.Create(ctx, managedZone)).To(Succeed()) gateway = NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace). + WithHTTPListener("foo", "foo.example.com"). WithHTTPListener(TestListenerNameOne, TestHostOne). WithHTTPListener(TestListenerNameWildcard, TestHostWildcard). Gateway @@ -71,6 +73,12 @@ var _ = Describe("DNSPolicy Single Cluster", func() { }, } gateway.Status.Listeners = []gatewayapiv1.ListenerStatus{ + { + Name: "foo", + SupportedKinds: []gatewayapiv1.RouteGroupKind{}, + AttachedRoutes: 0, + Conditions: []metav1.Condition{}, + }, { Name: TestListenerNameOne, SupportedKinds: []gatewayapiv1.RouteGroupKind{}, @@ -122,6 +130,21 @@ var _ = Describe("DNSPolicy Single Cluster", func() { }) It("should create dns records", func() { + + Eventually(func(g Gomega, ctx context.Context) { + + g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy)).To(Succeed()) + g.Expect(dnsPolicy.Status.Conditions).To( + ContainElement(MatchFields(IgnoreExtras, Fields{ + "Type": Equal(string(kuadrant.PolicyConditionEnforced)), + "Status": Equal(metav1.ConditionFalse), + "Reason": Equal(string(kuadrant.PolicyReasonEnforced)), + "Message": Equal("DNSPolicy has been partially enforced"), + })), + ) + + }, TestTimeoutMedium, TestRetryIntervalMedium, ctx).Should(Succeed()) + Eventually(func(g Gomega, ctx context.Context) { recordList := &kuadrantdnsv1alpha1.DNSRecordList{} err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) diff --git a/controllers/dnspolicy_dnsrecords.go b/controllers/dnspolicy_dnsrecords.go index 324bd477d..1b07f1c62 100644 --- a/controllers/dnspolicy_dnsrecords.go +++ b/controllers/dnspolicy_dnsrecords.go @@ -90,7 +90,7 @@ func (r *DNSPolicyReconciler) reconcileGatewayDNSRecords(ctx context.Context, gw if err := r.dnsHelper.deleteDNSRecordForListener(ctx, gatewayWrapper, listener); client.IgnoreNotFound(err) != nil { return fmt.Errorf("failed to delete dns record for listener %s : %w", listener.Name, err) } - return nil + continue } dnsRecord, err := r.desiredDNSRecord(gatewayWrapper, dnsPolicy, listener, listenerGateways, mz)