Skip to content

Commit

Permalink
Merge pull request #207 from gardener/fix-domain-selection-dot-uppercase
Browse files Browse the repository at this point in the history
Fix provider domain selection: allow final dot and uppercase
  • Loading branch information
mandelsoft authored Sep 1, 2021
2 parents 16e5a73 + 4b03377 commit 98fae76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand Down
17 changes: 15 additions & 2 deletions pkg/dns/provider/selection/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
}
26 changes: 26 additions & 0 deletions pkg/dns/provider/selection/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 98fae76

Please sign in to comment.