Skip to content

Commit c882eb5

Browse files
wenyingdcursoragent
andcommitted
feat(dns): implement NSX Project DNS record service
- Implement DNSRecordService for NSX ProjectDnsRecord CRUD operations - Validate hostnames against VPCNetworkConfiguration allowed DNS zones - Wrap hostname-mismatch error as DNSZoneValidationError for accurate DNSRecordReady condition reporting Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ff79596 commit c882eb5

42 files changed

Lines changed: 4950 additions & 16 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ require (
3434
github.com/vmware/govmomi v0.53.1
3535
github.com/vmware/vsphere-automation-sdk-go/lib v0.8.0
3636
github.com/vmware/vsphere-automation-sdk-go/runtime v0.8.0
37-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260310075027-d32fca6a7b22
38-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260310075027-d32fca6a7b22
37+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260429104618-0417fff4645f
38+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260429104618-0417fff4645f
3939
go.uber.org/automaxprocs v1.6.0
4040
go.uber.org/zap v1.27.1
4141
golang.org/x/crypto v0.50.0
42+
golang.org/x/net v0.53.0
4243
golang.org/x/sync v0.20.0
4344
golang.org/x/time v0.14.0
4445
gopkg.in/ini.v1 v1.67.1
@@ -108,7 +109,6 @@ require (
108109
go.yaml.in/yaml/v2 v2.4.4 // indirect
109110
go.yaml.in/yaml/v3 v3.0.4 // indirect
110111
golang.org/x/mod v0.35.0 // indirect
111-
golang.org/x/net v0.53.0 // indirect
112112
golang.org/x/oauth2 v0.36.0 // indirect
113113
golang.org/x/sys v0.43.0 // indirect
114114
golang.org/x/term v0.42.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ github.com/vmware/vsphere-automation-sdk-go/lib v0.8.0 h1:u1SXOTM6D4Ygb3jeidj2Rd
175175
github.com/vmware/vsphere-automation-sdk-go/lib v0.8.0/go.mod h1:8d5JTwjpM/Z03n/IZb0fwmXkJNWvWwuLXBqoakqYio4=
176176
github.com/vmware/vsphere-automation-sdk-go/runtime v0.8.0 h1:KnDIX9LY0nru7iMQTg0sy9vChhyorPo5OdASM2MaAcI=
177177
github.com/vmware/vsphere-automation-sdk-go/runtime v0.8.0/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c=
178-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260310075027-d32fca6a7b22 h1:yDMJj+UG0u9aDdC0Q1byw8QEjfPd8gm7QKB2mo2oU1I=
179-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260310075027-d32fca6a7b22/go.mod h1:C3JVOHRVLrGBQ8kTWAiGYlRz5UQC5qAcTdt3tvA+5P0=
180-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260310075027-d32fca6a7b22 h1:SKbUc9p+LFUwtPvjk9WCwrjstN6NpewgPx4eWSIZq+k=
181-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260310075027-d32fca6a7b22/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc=
178+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260429104618-0417fff4645f h1:giI6VdAbSQ40fwpRjLow2S9iWNJ3ywJAST61WJ9ZxZU=
179+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260429104618-0417fff4645f/go.mod h1:C3JVOHRVLrGBQ8kTWAiGYlRz5UQC5qAcTdt3tvA+5P0=
180+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260429104618-0417fff4645f h1:Y3Nn/DkcjEZFBGAoXRPj6r8Q4Av8ZL2mwXdgL1hpETk=
181+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260429104618-0417fff4645f/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc=
182182
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
183183
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
184184
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=

pkg/clean/clean.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/vmware-tanzu/nsx-operator/pkg/logger"
1313
"github.com/vmware-tanzu/nsx-operator/pkg/nsx"
1414
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
15+
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/dns"
1516
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/inventory"
1617
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/ipaddressallocation"
1718
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/nsxserviceaccount"
@@ -115,6 +116,10 @@ func InitializeCleanupService(cf *config.NSXOperatorConfig, nsxClient *nsx.Clien
115116
if err != nil {
116117
return nil, err
117118
}
119+
dnsRecordService, err := dns.InitializeDNSRecordService(commonService, vpcService)
120+
if err != nil {
121+
return nil, err
122+
}
118123
subnetPortService, err := subnetport.InitializeSubnetPort(commonService, vpcService, ipAddressAllocationService)
119124
if err != nil {
120125
return nil, err
@@ -155,6 +160,11 @@ func InitializeCleanupService(cf *config.NSXOperatorConfig, nsxClient *nsx.Clien
155160
return ipAddressAllocationService, nil
156161
}
157162
}
163+
wrapInitializeDNSRecordService := func(service common.Service) cleanupFunc {
164+
return func() (interface{}, error) {
165+
return dnsRecordService, nil
166+
}
167+
}
158168
wrapInitializeSubnetBinding := func(service common.Service) cleanupFunc {
159169
return func() (interface{}, error) {
160170
return subnetbinding.InitializeService(service)
@@ -213,6 +223,7 @@ func InitializeCleanupService(cf *config.NSXOperatorConfig, nsxClient *nsx.Clien
213223
loggedAdd("StaticRoute", wrapInitializeStaticRoute(commonService))
214224
loggedAdd("VPC", wrapInitializeVPC(commonService))
215225
loggedAdd("IPAddressAllocation", wrapInitializeIPAddressAllocation(commonService))
226+
loggedAdd("DNSRecord", wrapInitializeDNSRecordService(commonService))
216227
loggedAdd("Inventory", wrapInitializeInventory(commonService))
217228
loggedAdd("LBInfraCleaner", wrapInitializeLBInfraCleaner(commonService))
218229
loggedAdd("HealthCleaner", wrapInitializeHealthCleaner(commonService))

pkg/clean/clean_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/vmware-tanzu/nsx-operator/pkg/config"
1515
"github.com/vmware-tanzu/nsx-operator/pkg/nsx"
1616
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
17+
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/dns"
1718
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/inventory"
1819
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/ipaddressallocation"
1920
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/nsxserviceaccount"
@@ -187,6 +188,9 @@ func TestInitializeCleanupService_Success(t *testing.T) {
187188
patches.ApplyFunc(ipaddressallocation.InitializeIPAddressAllocation, func(service common.Service, vpcService common.VPCServiceProvider, flag bool) (*ipaddressallocation.IPAddressAllocationService, error) {
188189
return &ipaddressallocation.IPAddressAllocationService{}, nil
189190
})
191+
patches.ApplyFunc(dns.InitializeDNSRecordService, func(service common.Service, vpcService common.VPCServiceProvider) (*dns.DNSRecordService, error) {
192+
return &dns.DNSRecordService{}, nil
193+
})
190194
patches.ApplyFunc(subnetbinding.InitializeService, func(service common.Service) (*subnetbinding.BindingService, error) {
191195
return &subnetbinding.BindingService{}, nil
192196
})
@@ -216,7 +220,7 @@ func TestInitializeCleanupService_Success(t *testing.T) {
216220
// vpcPreCleaners: SubnetPort, SubnetBinding, SubnetIPReservation, Inventory, SecurityPolicy, LBInfraCleaner, NSXServiceAccount, HealthCleaner = 8
217221
assert.Len(t, cleanupService.vpcPreCleaners, 7)
218222
assert.Len(t, cleanupService.vpcChildrenCleaners, 5)
219-
assert.Len(t, cleanupService.infraCleaners, 2)
223+
assert.Len(t, cleanupService.infraCleaners, 3)
220224
}
221225

222226
func TestInitializeCleanupService_VPCError(t *testing.T) {
@@ -245,6 +249,9 @@ func TestInitializeCleanupService_VPCError(t *testing.T) {
245249
patches.ApplyFunc(ipaddressallocation.InitializeIPAddressAllocation, func(service common.Service, vpcService common.VPCServiceProvider, flag bool) (*ipaddressallocation.IPAddressAllocationService, error) {
246250
return &ipaddressallocation.IPAddressAllocationService{}, nil
247251
})
252+
patches.ApplyFunc(dns.InitializeDNSRecordService, func(service common.Service, vpcService common.VPCServiceProvider) (*dns.DNSRecordService, error) {
253+
return &dns.DNSRecordService{}, nil
254+
})
248255
patches.ApplyFunc(subnetbinding.InitializeService, func(service common.Service) (*subnetbinding.BindingService, error) {
249256
return &subnetbinding.BindingService{}, nil
250257
})

pkg/mock/dnsrecordprovider/client.go

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/mock/dnsrecordprovider/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package mocks provides MockDNSRecordProvider for dns.DNSRecordProvider.
2+
// client.go is hand-written: github.com/golang/mock/mockgen@v1.6 cannot parse generic sets.Set in interface methods.
3+
package mocks

pkg/mock/dnsrecordsclient/client.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/mock/dnsrecordsclient/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package mocks contains a generated mock for projects.DnsRecordsClient.
2+
//
3+
//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -destination=client.go -package=mocks github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects DnsRecordsClient
4+
package mocks

0 commit comments

Comments
 (0)