Add trailing dot to NS records in Google Cloud DNS

NS records added in Google Cloud DNS must have a trailing dot. Otherwise the API throws the following error:
```
time="2024-11-04T10:34:20Z" level=error msg="googleapi: Error 400: Invalid value for 'entity.change.additions[cloud.k8gb.io.][NS].rrdata[0]': 'gslb-ns-eu-cloud.k8gb.io', invalid"
```
This is similar to CNAME, MX and SRV records.

---

This change was tested with the a DNSEndpoint CRD containing the following endpoints:
```
    endpoints:
    - dnsName: cloud.k8gb.io
      recordTTL: 5
      recordType: NS
      targets:
      - gslb-ns-eu-cloud.k8gb.io
      - gslb-ns-us-cloud.k8gb.io
    - dnsName: gslb-ns-eu-cloud.k8gb.io
```
And the record was successfully created
```
gcloud dns record-sets list --zone="k8gb" --type=NS --name "cloud.k8gb.io."
NAME            TYPE  TTL  DATA
cloud.k8gb.io.  NS    5    gslb-ns-eu-cloud.k8gb.io.,gslb-ns-us-cloud.k8gb.io.
```

Signed-off-by: Andre Aguas <andre.aguas@protonmail.com>
This commit is contained in:
Andre Aguas 2024-11-04 23:26:55 +01:00
parent b2ec5228ec
commit 1fc97ec54a

View File

@ -445,6 +445,12 @@ func newRecord(ep *endpoint.Endpoint) *dns.ResourceRecordSet {
}
}
if ep.RecordType == endpoint.RecordTypeNS {
for i, nsRecord := range ep.Targets {
targets[i] = provider.EnsureTrailingDot(nsRecord)
}
}
// no annotation results in a Ttl of 0, default to 300 for backwards-compatibility
var ttl int64 = googleRecordTTL
if ep.RecordTTL.IsConfigured() {