Skip to content

Commit

Permalink
Merge pull request #4846 from abaguas/azure/nsrecords
Browse files Browse the repository at this point in the history
feat(Azure DNS): add NS record support
  • Loading branch information
k8s-ci-robot authored Dec 15, 2024
2 parents cd172f2 + c2dc4bd commit 2a45cc8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
23 changes: 23 additions & 0 deletions provider/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,19 @@ func (p *AzureProvider) newRecordSet(endpoint *endpoint.Endpoint) (dns.RecordSet
MxRecords: mxRecords,
},
}, nil
case dns.RecordTypeNS:
nsRecords := make([]*dns.NsRecord, len(endpoint.Targets))
for i, target := range endpoint.Targets {
nsRecords[i] = &dns.NsRecord{
Nsdname: to.Ptr(target),
}
}
return dns.RecordSet{
Properties: &dns.RecordSetProperties{
TTL: to.Ptr(ttl),
NsRecords: nsRecords,
},
}, nil
case dns.RecordTypeTXT:
return dns.RecordSet{
Properties: &dns.RecordSetProperties{
Expand Down Expand Up @@ -460,6 +473,16 @@ func extractAzureTargets(recordSet *dns.RecordSet) []string {
return targets
}

// Check for NS records
nsRecords := properties.NsRecords
if len(nsRecords) > 0 && (nsRecords)[0].Nsdname != nil {
targets := make([]string, len(nsRecords))
for i, nsRecord := range nsRecords {
targets[i] = *nsRecord.Nsdname
}
return targets
}

// Check for TXT records
txtRecords := properties.TxtRecords
if len(txtRecords) > 0 && (txtRecords)[0].Value != nil {
Expand Down
8 changes: 4 additions & 4 deletions provider/azure/azure_privatedns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ func TestAzurePrivateDNSApplyChanges(t *testing.T) {
}

func TestAzurePrivateDNSApplyChangesDryRun(t *testing.T) {
recordsClient := mockRecordSetsClient{}
recordsClient := mockPrivateRecordSetsClient{}

testAzureApplyChangesInternal(t, true, &recordsClient)
testAzurePrivateDNSApplyChangesInternal(t, true, &recordsClient)

validateAzureEndpoints(t, recordsClient.deletedEndpoints, []*endpoint.Endpoint{})

Expand Down Expand Up @@ -471,9 +471,9 @@ func TestAzurePrivateDNSNameFilter(t *testing.T) {
}

func TestAzurePrivateDNSApplyChangesZoneName(t *testing.T) {
recordsClient := mockRecordSetsClient{}
recordsClient := mockPrivateRecordSetsClient{}

testAzureApplyChangesInternalZoneName(t, false, &recordsClient)
testAzurePrivateDNSApplyChangesInternalZoneName(t, false, &recordsClient)

validateAzureEndpoints(t, recordsClient.deletedEndpoints, []*endpoint.Endpoint{
endpoint.NewEndpoint("deleted.foo.example.com", endpoint.RecordTypeA, ""),
Expand Down
Loading

0 comments on commit 2a45cc8

Please sign in to comment.