From 1fc97ec54a643ca09f3f892ed405362a749fc419 Mon Sep 17 00:00:00 2001 From: Andre Aguas Date: Mon, 4 Nov 2024 23:26:55 +0100 Subject: [PATCH 1/3] 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 --- provider/google/google.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/provider/google/google.go b/provider/google/google.go index 3502d6474..a3222ad59 100644 --- a/provider/google/google.go +++ b/provider/google/google.go @@ -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() { From 43b69631983e151add955cc3f22741f8fd188079 Mon Sep 17 00:00:00 2001 From: Andre Aguas Date: Thu, 14 Nov 2024 17:02:51 +0100 Subject: [PATCH 2/3] add unit tests Signed-off-by: Andre Aguas --- provider/google/google_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/provider/google/google_test.go b/provider/google/google_test.go index 89a51b08b..1e906eeb2 100644 --- a/provider/google/google_test.go +++ b/provider/google/google_test.go @@ -465,21 +465,25 @@ func TestNewFilteredRecords(t *testing.T) { endpoint.NewEndpointWithTTL("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 1, "8.8.4.4"), endpoint.NewEndpointWithTTL("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 120, "8.8.4.4"), endpoint.NewEndpointWithTTL("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeCNAME, 4000, "bar.elb.amazonaws.com"), + endpoint.NewEndpointWithTTL("update-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeNS, 120, "foo.elb.amazonaws.com"), // test fallback to Ttl:300 when Ttl==0 : endpoint.NewEndpointWithTTL("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 0, "8.8.8.8"), endpoint.NewEndpointWithTTL("update-test-mx.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeMX, 6000, "10 mail.elb.amazonaws.com"), endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, "8.8.8.8"), endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeCNAME, "qux.elb.amazonaws.com"), + endpoint.NewEndpoint("delete-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeNS, "foo.elb.amazonaws.com"), }) validateChangeRecords(t, records, []*dns.ResourceRecordSet{ {Name: "update-test.zone-2.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"8.8.4.4"}, Type: "A", Ttl: 1}, {Name: "delete-test.zone-2.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"8.8.4.4"}, Type: "A", Ttl: 120}, {Name: "update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"bar.elb.amazonaws.com."}, Type: "CNAME", Ttl: 4000}, + {Name: "update-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"foo.elb.amazonaws.com."}, Type: "NS", Ttl: 120}, {Name: "update-test.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"8.8.8.8"}, Type: "A", Ttl: 300}, {Name: "update-test-mx.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"10 mail.elb.amazonaws.com."}, Type: "MX", Ttl: 6000}, {Name: "delete-test.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"8.8.8.8"}, Type: "A", Ttl: 300}, {Name: "delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"qux.elb.amazonaws.com."}, Type: "CNAME", Ttl: 300}, + {Name: "delete-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do.", Rrdatas: []string{"foo.elb.amazonaws.com."}, Type: "NS", Ttl: 300}, }) } From a6aa77ddcdc423bfc7bc925a2fc4b0645b3da2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=C3=81guas?= Date: Thu, 14 Nov 2024 17:16:42 +0100 Subject: [PATCH 3/3] Update provider/google/google_test.go Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com> --- provider/google/google_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/google/google_test.go b/provider/google/google_test.go index 1e906eeb2..0cec40a38 100644 --- a/provider/google/google_test.go +++ b/provider/google/google_test.go @@ -465,7 +465,7 @@ func TestNewFilteredRecords(t *testing.T) { endpoint.NewEndpointWithTTL("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 1, "8.8.4.4"), endpoint.NewEndpointWithTTL("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 120, "8.8.4.4"), endpoint.NewEndpointWithTTL("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeCNAME, 4000, "bar.elb.amazonaws.com"), - endpoint.NewEndpointWithTTL("update-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeNS, 120, "foo.elb.amazonaws.com"), + endpoint.NewEndpointWithTTL("update-test-ns.zone-1.ext-dns-test-2.gcp.zalan.do.", endpoint.RecordTypeNS, 120, "foo.elb.amazonaws.com"), // test fallback to Ttl:300 when Ttl==0 : endpoint.NewEndpointWithTTL("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeA, 0, "8.8.8.8"), endpoint.NewEndpointWithTTL("update-test-mx.zone-1.ext-dns-test-2.gcp.zalan.do", endpoint.RecordTypeMX, 6000, "10 mail.elb.amazonaws.com"),