@@ -25,6 +25,7 @@ import (
2525 mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile"
2626
2727 networkingv1alpha "go.datum.net/network-services-operator/api/v1alpha"
28+ dnsutil "go.datum.net/network-services-operator/internal/util/dns"
2829 dnsv1alpha1 "go.miloapis.com/dns-operator/api/v1alpha1"
2930)
3031
@@ -102,7 +103,7 @@ func (r *GatewayReconciler) ensureDNSRecordSets(
102103 continue
103104 }
104105
105- // Find the most specific Domain + DNSZone combination.
106+ // Find the most specific Domain + DNSZone combination where Datum DNS has authority .
106107 var domain * networkingv1alpha.Domain
107108 var dnsZone * dnsv1alpha1.DNSZone
108109 var matchedZoneName string
@@ -114,10 +115,9 @@ func (r *GatewayReconciler) ensureDNSRecordSets(
114115 continue
115116 }
116117
117- // Check if the Domain has VerifiedDNSZone=True.
118- if ! apimeta .IsStatusConditionTrue (d .Status .Conditions , networkingv1alpha .DomainConditionVerifiedDNSZone ) {
119- // Domain exists but isn't verified; record this for potential error message
120- // but keep looking for a more specific verified domain.
118+ // Check if the Domain is verified (ownership proven via any method).
119+ if ! apimeta .IsStatusConditionTrue (d .Status .Conditions , networkingv1alpha .DomainConditionVerified ) {
120+ // Domain exists but isn't verified; keep looking.
121121 continue
122122 }
123123
@@ -135,36 +135,87 @@ func (r *GatewayReconciler) ensureDNSRecordSets(
135135 continue
136136 }
137137
138- // Found a matching Domain + DNSZone.
138+ // Check if Datum DNS has authority (DNSZone ready + nameservers match).
139+ zone := & dnsZoneList .Items [0 ]
140+ if ! dnsutil .HasDNSAuthority (& d , zone ) {
141+ // Domain verified but Datum DNS doesn't have authority yet.
142+ continue
143+ }
144+
145+ // Found a matching Domain + DNSZone where Datum DNS has authority.
139146 domain = & d
140- dnsZone = & dnsZoneList . Items [ 0 ]
147+ dnsZone = zone
141148 matchedZoneName = zoneName
142149 break
143150 }
144151
145152 // If no matching Domain + DNSZone found, check why and set appropriate status.
146153 if domain == nil || dnsZone == nil {
147154 // Try to provide a helpful message by checking what we found.
148- var unverifiedDomain * networkingv1alpha.Domain
155+ var (
156+ unverifiedDomain * networkingv1alpha.Domain
157+ noAuthorityDomain * networkingv1alpha.Domain
158+ noAuthorityZone * dnsv1alpha1.DNSZone
159+ )
149160 for _ , zoneName := range zoneNames {
150161 d , found := findDomainByName (domainList .Items , zoneName )
151- if found {
152- if ! apimeta .IsStatusConditionTrue (d .Status .Conditions , networkingv1alpha .DomainConditionVerifiedDNSZone ) {
153- unverifiedDomain = & d
154- break
155- }
162+ if ! found {
163+ continue
164+ }
165+
166+ // Check if domain is verified
167+ if ! apimeta .IsStatusConditionTrue (d .Status .Conditions , networkingv1alpha .DomainConditionVerified ) {
168+ unverifiedDomain = & d
169+ break
170+ }
171+
172+ // Domain is verified; check if there's a DNSZone
173+ var dnsZoneList dnsv1alpha1.DNSZoneList
174+ if err := upstreamClient .List (ctx , & dnsZoneList ,
175+ client .InNamespace (upstreamGateway .Namespace ),
176+ client.MatchingFields {dnsZoneDomainNameIndex : zoneName },
177+ ); err != nil {
178+ continue
156179 }
180+ if len (dnsZoneList .Items ) == 0 {
181+ continue
182+ }
183+
184+ // DNSZone exists but Datum DNS doesn't have authority
185+ noAuthorityDomain = & d
186+ noAuthorityZone = & dnsZoneList .Items [0 ]
187+ break
157188 }
158189
159- if unverifiedDomain != nil {
190+ switch {
191+ case unverifiedDomain != nil :
160192 apimeta .SetStatusCondition (& hs .Conditions , metav1.Condition {
161193 Type : networkingv1alpha .HostnameConditionDNSRecordProgrammed ,
162194 Status : metav1 .ConditionFalse ,
163195 Reason : networkingv1alpha .DNSRecordReasonDomainNotVerified ,
164- Message : fmt .Sprintf ("Domain %q has not been verified via a DNSZone (VerifiedDNSZone condition is not True)" , unverifiedDomain .Name ),
196+ Message : fmt .Sprintf ("Domain %q ownership has not been verified" , unverifiedDomain .Name ),
197+ ObservedGeneration : upstreamGateway .Generation ,
198+ })
199+ case noAuthorityDomain != nil :
200+ msg := fmt .Sprintf ("Domain %q is verified but Datum DNS does not have authority" , noAuthorityDomain .Name )
201+ if noAuthorityZone != nil {
202+ if ! apimeta .IsStatusConditionTrue (noAuthorityZone .Status .Conditions , "Accepted" ) ||
203+ ! apimeta .IsStatusConditionTrue (noAuthorityZone .Status .Conditions , "Programmed" ) {
204+ msg = fmt .Sprintf ("DNSZone %q is not ready (waiting for Accepted and Programmed conditions)" , noAuthorityZone .Name )
205+ } else if len (noAuthorityZone .Status .Nameservers ) == 0 {
206+ msg = fmt .Sprintf ("DNSZone %q has no nameservers assigned yet" , noAuthorityZone .Name )
207+ } else {
208+ msg = fmt .Sprintf ("Domain %q nameservers do not include DNSZone %q nameservers; update your registrar's NS records" , noAuthorityDomain .Name , noAuthorityZone .Name )
209+ }
210+ }
211+ apimeta .SetStatusCondition (& hs .Conditions , metav1.Condition {
212+ Type : networkingv1alpha .HostnameConditionDNSRecordProgrammed ,
213+ Status : metav1 .ConditionFalse ,
214+ Reason : networkingv1alpha .DNSRecordReasonDNSAuthorityMissing ,
215+ Message : msg ,
165216 ObservedGeneration : upstreamGateway .Generation ,
166217 })
167- } else {
218+ default :
168219 apimeta .SetStatusCondition (& hs .Conditions , metav1.Condition {
169220 Type : networkingv1alpha .HostnameConditionDNSRecordProgrammed ,
170221 Status : metav1 .ConditionTrue ,
0 commit comments