@@ -6,6 +6,8 @@ package networkinfo
66import (
77 "context"
88 "fmt"
9+ "maps"
10+ "slices"
911 "time"
1012
1113 stderrors "github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors"
7072 nsMsgVPCAutoSNATDisabled = newNsUnreadyMessage ("SNAT is not enabled in System VPC" , NSReasonVPCSnatNotReady )
7173 nsMsgVPCDefaultSNATIPGetError = newNsUnreadyMessage ("Default SNAT IP is not allocated in VPC: %v" , NSReasonVPCSnatNotReady )
7274 nsMsgVPCIsReady = newNsUnreadyMessage ("" , "" )
75+ nsMsgVPCDNSZonesSyncError = newNsUnreadyMessage ("Failed to sync permitted DNS zones from NSX: %v" , NSReasonVPCNotReady )
7376)
7477
7578type nsUnreadyMessage struct {
@@ -97,12 +100,18 @@ func (m *nsUnreadyMessage) getNSNetworkCondition(options ...interface{}) *corev1
97100 return cond
98101}
99102
103+ // dnsZoneSyncer is the minimal DNS interface needed by NetworkInfoReconciler for VPC DNS zone lookups.
104+ type dnsZoneSyncer interface {
105+ SyncDNSZonesByVpcNetworkConfig (vpcConfig * v1alpha1.VPCNetworkConfiguration ) (map [string ]string , error )
106+ }
107+
100108// NetworkInfoReconciler NetworkInfoReconcile reconciles a NetworkInfo object
101109// Actually it is more like a shell, which is used to manage nsx VPC
102110type NetworkInfoReconciler struct {
103111 Client client.Client
104112 Scheme * apimachineryruntime.Scheme
105113 Service * vpc.VPCService
114+ DNSRecordService dnsZoneSyncer
106115 IPBlocksInfoService * ipblocksinfo.IPBlocksInfoService
107116 Recorder record.EventRecorder
108117 queue workqueue.TypedRateLimitingInterface [reconcile.Request ]
@@ -430,9 +439,29 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request)
430439 NetworkStack : networkStack ,
431440 }
432441
442+ var allowedDNSDomains []string
443+ if r .DNSRecordService != nil && len (nc .Spec .DNSZones ) > 0 {
444+ zoneMap , err := r .DNSRecordService .SyncDNSZonesByVpcNetworkConfig (nc )
445+ if err != nil {
446+ r .StatusUpdater .UpdateFail (ctx , networkInfoCR , err , "Failed to sync DNS zones for VPC network configuration" , setNetworkInfoVPCStatusWithError , state )
447+ setNSNetworkReadyCondition (ctx , r .Client , req .Namespace , nsMsgVPCDNSZonesSyncError .getNSNetworkCondition (err ))
448+ return common .ResultRequeueAfter10sec , err
449+ }
450+ // Use a Set to ensure each domain name in the allowed list is unique.
451+ domainNamesSet := sets .New [string ]()
452+ for _ , domainName := range slices .Sorted (maps .Values (zoneMap )) {
453+ if domainName == "" {
454+ continue
455+ }
456+ domainNamesSet .Insert (domainName )
457+ }
458+ allowedDNSDomains = domainNamesSet .UnsortedList ()
459+ slices .Sort (allowedDNSDomains )
460+ }
461+
433462 // AKO needs to know the AVI subnet path created by NSX
434463 setVPCNetworkConfigurationStatusWithLBS (ctx , r .Client , ncName , state .Name , aviSubnetPath , nsxLBSPath , * createdVpc .Path )
435- r .StatusUpdater .UpdateSuccess (ctx , networkInfoCR , setNetworkInfoVPCStatus , state )
464+ r .StatusUpdater .UpdateSuccess (ctx , networkInfoCR , setNetworkInfoVPCStatus , state , allowedDNSDomains )
436465
437466 if retryWithSystemVPC {
438467 setNSNetworkReadyCondition (ctx , r .Client , req .Namespace , systemNSCondition )
@@ -805,11 +834,12 @@ func (r *NetworkInfoReconciler) StartController(mgr ctrl.Manager, _ webhook.Serv
805834 return nil
806835}
807836
808- func NewNetworkInfoReconciler (mgr ctrl.Manager , vpcService * vpc.VPCService , ipblocksInfoService * ipblocksinfo.IPBlocksInfoService ) * NetworkInfoReconciler {
837+ func NewNetworkInfoReconciler (mgr ctrl.Manager , vpcService * vpc.VPCService , ipblocksInfoService * ipblocksinfo.IPBlocksInfoService , dnsRecordService dnsZoneSyncer ) * NetworkInfoReconciler {
809838 networkInfoReconciler := & NetworkInfoReconciler {
810- Client : mgr .GetClient (),
811- Scheme : mgr .GetScheme (),
812- Recorder : mgr .GetEventRecorderFor ("networkinfo-controller" ),
839+ Client : mgr .GetClient (),
840+ Scheme : mgr .GetScheme (),
841+ DNSRecordService : dnsRecordService ,
842+ Recorder : mgr .GetEventRecorderFor ("networkinfo-controller" ),
813843 }
814844 networkInfoReconciler .Service = vpcService
815845 networkInfoReconciler .IPBlocksInfoService = ipblocksInfoService
0 commit comments