From 4b03377220a31bf83eaddb21539dbe66f3f9b84f Mon Sep 17 00:00:00 2001 From: Martin Weindel Date: Mon, 30 Aug 2021 13:35:15 +0200 Subject: [PATCH] fix provider domain selection: allow final dot and uppercase --- build/Dockerfile | 2 +- pkg/dns/provider/selection/selection.go | 17 +++++++++++-- pkg/dns/provider/selection/selection_test.go | 26 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index ad60f2336..d825aba44 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. ############# builder ############# -FROM eu.gcr.io/gardener-project/3rd/golang:1.16.6 AS builder +FROM eu.gcr.io/gardener-project/3rd/golang:1.16.7 AS builder WORKDIR /build COPY . . diff --git a/pkg/dns/provider/selection/selection.go b/pkg/dns/provider/selection/selection.go index dd3822d53..37f7c68a8 100644 --- a/pkg/dns/provider/selection/selection.go +++ b/pkg/dns/provider/selection/selection.go @@ -101,11 +101,11 @@ func CalcZoneAndDomainSelection(spec v1alpha1.DNSProviderSpec, zones []LightDNSH } var err error - this.DomainSel.Include, err = filterByZones(this.SpecDomainSel.Include, this.Zones) + this.DomainSel.Include, err = filterByZones(normalizeDomains(this.SpecDomainSel.Include), this.Zones) if err != nil { this.Warnings = append(this.Warnings, err.Error()) } - this.DomainSel.Exclude, err = filterByZones(this.SpecDomainSel.Exclude, this.Zones) + this.DomainSel.Exclude, err = filterByZones(normalizeDomains(this.SpecDomainSel.Exclude), this.Zones) if err != nil { this.Warnings = append(this.Warnings, err.Error()) } @@ -225,3 +225,16 @@ func collectForwardedSubdomains(includedDomains utils.StringSet, excludedDomains } return include, exclude } + +func normalizeDomains(domains utils.StringSet) utils.StringSet { + if len(domains) == 0 { + return domains + } + + normalized := utils.NewStringSet() + for k := range domains { + k = strings.TrimSuffix(strings.ToLower(k), ".") + normalized.Add(k) + } + return normalized +} diff --git a/pkg/dns/provider/selection/selection_test.go b/pkg/dns/provider/selection/selection_test.go index f93c5d983..97a047015 100644 --- a/pkg/dns/provider/selection/selection_test.go +++ b/pkg/dns/provider/selection/selection_test.go @@ -74,6 +74,32 @@ var _ = Describe("Selection", func() { })) }) + It("deals with uppercase domain selection and final dot", func() { + spec := v1alpha1.DNSProviderSpec{ + Domains: &v1alpha1.DNSSelection{ + Include: []string{"A.b."}, + Exclude: []string{"O.P."}, + }, + } + result := CalcZoneAndDomainSelection(spec, allzones) + Expect(result).To(Equal(SelectionResult{ + Zones: []LightDNSHostedZone{zab, zcab}, + SpecZoneSel: NewSubSelection(), + SpecDomainSel: SubSelection{ + Include: utils.NewStringSet("A.b."), + Exclude: utils.NewStringSet("O.P."), + }, + ZoneSel: SubSelection{ + Include: utils.NewStringSet("ZAB", "ZCAB"), + Exclude: utils.NewStringSet("ZOP"), + }, + DomainSel: SubSelection{ + Include: utils.NewStringSet("a.b", "c.a.b"), + Exclude: utils.NewStringSet("d.a.b", "o.p"), + }, + })) + }) + It("handles no zones", func() { spec := v1alpha1.DNSProviderSpec{} result := CalcZoneAndDomainSelection(spec, nozones)