Skip to content

Commit d5459d9

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 6ae0434 commit d5459d9

38 files changed

Lines changed: 3950 additions & 17 deletions

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ require (
3535
github.com/vmware/govmomi v0.53.1
3636
github.com/vmware/vsphere-automation-sdk-go/lib v0.8.0
3737
github.com/vmware/vsphere-automation-sdk-go/runtime v0.8.0
38-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260310075027-d32fca6a7b22
39-
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260310075027-d32fca6a7b22
38+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.0.0-20260429104618-0417fff4645f
39+
github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20260429104618-0417fff4645f
4040
go.openly.dev/pointy v1.3.0
4141
go.uber.org/automaxprocs v1.6.0
4242
go.uber.org/zap v1.27.1
4343
golang.org/x/crypto v0.50.0
44+
golang.org/x/net v0.53.0
4445
golang.org/x/sync v0.20.0
4546
golang.org/x/time v0.14.0
4647
gopkg.in/ini.v1 v1.67.1
@@ -51,6 +52,7 @@ require (
5152
k8s.io/code-generator v0.35.1
5253
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2
5354
sigs.k8s.io/controller-runtime v0.23.3
55+
sigs.k8s.io/gateway-api v1.5.1
5456
)
5557

5658
require (
@@ -92,7 +94,6 @@ require (
9294
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
9395
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
9496
github.com/onsi/ginkgo/v2 v2.28.1 // indirect
95-
github.com/onsi/gomega v1.39.1 // indirect
9697
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
9798
github.com/prometheus/client_model v0.6.2 // indirect
9899
github.com/prometheus/common v0.67.5 // indirect
@@ -104,7 +105,6 @@ require (
104105
go.yaml.in/yaml/v2 v2.4.4 // indirect
105106
go.yaml.in/yaml/v3 v3.0.4 // indirect
106107
golang.org/x/mod v0.35.0 // indirect
107-
golang.org/x/net v0.53.0 // indirect
108108
golang.org/x/oauth2 v0.36.0 // indirect
109109
golang.org/x/sys v0.43.0 // indirect
110110
golang.org/x/term v0.42.0 // indirect

go.sum

Lines changed: 6 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.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
@@ -303,6 +303,8 @@ k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0x
303303
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
304304
sigs.k8s.io/controller-runtime v0.23.3 h1:VjB/vhoPoA9l1kEKZHBMnQF33tdCLQKJtydy4iqwZ80=
305305
sigs.k8s.io/controller-runtime v0.23.3/go.mod h1:B6COOxKptp+YaUT5q4l6LqUJTRpizbgf9KSRNdQGns0=
306+
sigs.k8s.io/gateway-api v1.5.1 h1:RqVRIlkhLhUO8wOHKTLnTJA6o/1un4po4/6M1nRzdd0=
307+
sigs.k8s.io/gateway-api v1.5.1/go.mod h1:GvCETiaMAlLym5CovLxGjS0NysqFk3+Yuq3/rh6QL2o=
306308
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
307309
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
308310
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=

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)