Skip to content

Commit 54552ba

Browse files
committed
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
1 parent 934da6b commit 54552ba

41 files changed

Lines changed: 4942 additions & 10 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
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

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)