mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
Align PDNS provider with other providers by removing MatchParent
PNDS provider is the only one which uses MatchParent functionality. The MatchParent functionality breaks domain and regex domain filters. It also makes PDNS provider behave differently than other providers while having the same configuration. MatchParent can be replaced by using multiple domain filters. After discussion with maintainers we concluded that MatchParent should be removed.
This commit is contained in:
parent
2e00d428f2
commit
7aa9d25067
@ -140,28 +140,6 @@ func matchRegex(regex *regexp.Regexp, negativeRegex *regexp.Regexp, domain strin
|
|||||||
return regex.MatchString(strippedDomain)
|
return regex.MatchString(strippedDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchParent checks wether DomainFilter matches a given parent domain.
|
|
||||||
func (df DomainFilter) MatchParent(domain string) bool {
|
|
||||||
if matchFilter(df.exclude, domain, false) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(df.Filters) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
strippedDomain := strings.ToLower(strings.TrimSuffix(domain, "."))
|
|
||||||
for _, filter := range df.Filters {
|
|
||||||
if filter == "" || strings.HasPrefix(filter, ".") {
|
|
||||||
// We don't check parents if the filter is prefixed with "."
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.HasSuffix(filter, "."+strippedDomain) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsConfigured returns true if any inclusion or exclusion rules have been specified.
|
// IsConfigured returns true if any inclusion or exclusion rules have been specified.
|
||||||
func (df DomainFilter) IsConfigured() bool {
|
func (df DomainFilter) IsConfigured() bool {
|
||||||
if df.regex != nil && df.regex.String() != "" {
|
if df.regex != nil && df.regex.String() != "" {
|
||||||
|
@ -439,107 +439,6 @@ func TestDomainFilterMatchWithEmptyFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDomainFilterMatchParent(t *testing.T) {
|
|
||||||
parentMatchTests := []domainFilterTest{
|
|
||||||
{
|
|
||||||
[]string{"a.example.com."},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
true,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"a.example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{" a.example.com "},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
true,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"a.example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{""},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
true,
|
|
||||||
map[string][]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{".a.example.com."},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
false,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {".a.example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"a.example.com.", "b.example.com"},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
true,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"a.example.com", "b.example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"a.example.com"},
|
|
||||||
[]string{},
|
|
||||||
[]string{"b.example.com"},
|
|
||||||
false,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"a.example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"example.com"},
|
|
||||||
[]string{},
|
|
||||||
[]string{"example.com"},
|
|
||||||
false,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"example.com"},
|
|
||||||
[]string{},
|
|
||||||
[]string{"anexample.com"},
|
|
||||||
false,
|
|
||||||
map[string][]string{
|
|
||||||
"include": {"example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{""},
|
|
||||||
[]string{},
|
|
||||||
[]string{""},
|
|
||||||
true,
|
|
||||||
map[string][]string{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for i, tt := range parentMatchTests {
|
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
|
||||||
domainFilter := NewDomainFilterWithExclusions(tt.domainFilter, tt.exclusions)
|
|
||||||
|
|
||||||
assertSerializes(t, domainFilter, tt.expectedSerialization)
|
|
||||||
deserialized := deserialize(t, map[string][]string{
|
|
||||||
"include": tt.domainFilter,
|
|
||||||
"exclude": tt.exclusions,
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, domain := range tt.domains {
|
|
||||||
assert.Equal(t, tt.expected, domainFilter.MatchParent(domain), "%v", domain)
|
|
||||||
assert.Equal(t, tt.expected, domainFilter.MatchParent(domain+"."), "%v", domain+".")
|
|
||||||
|
|
||||||
assert.Equal(t, tt.expected, deserialized.MatchParent(domain), "deserialized %v", domain)
|
|
||||||
assert.Equal(t, tt.expected, deserialized.MatchParent(domain+"."), "deserialized %v", domain+".")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRegexDomainFilter(t *testing.T) {
|
func TestRegexDomainFilter(t *testing.T) {
|
||||||
for i, tt := range regexDomainFilterTests {
|
for i, tt := range regexDomainFilterTests {
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
|
@ -166,7 +166,7 @@ func (c *PDNSAPIClient) ListZones() (zones []pgo.Zone, resp *http.Response, err
|
|||||||
func (c *PDNSAPIClient) PartitionZones(zones []pgo.Zone) (filteredZones []pgo.Zone, residualZones []pgo.Zone) {
|
func (c *PDNSAPIClient) PartitionZones(zones []pgo.Zone) (filteredZones []pgo.Zone, residualZones []pgo.Zone) {
|
||||||
if c.domainFilter.IsConfigured() {
|
if c.domainFilter.IsConfigured() {
|
||||||
for _, zone := range zones {
|
for _, zone := range zones {
|
||||||
if c.domainFilter.Match(zone.Name) || c.domainFilter.MatchParent(zone.Name) {
|
if c.domainFilter.Match(zone.Name) {
|
||||||
filteredZones = append(filteredZones, zone)
|
filteredZones = append(filteredZones, zone)
|
||||||
} else {
|
} else {
|
||||||
residualZones = append(residualZones, zone)
|
residualZones = append(residualZones, zone)
|
||||||
|
@ -1059,16 +1059,6 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSClientPartitionZones() {
|
|||||||
assert.Equal(suite.T(), partitionResultFilteredMultipleFilter, filteredZones)
|
assert.Equal(suite.T(), partitionResultFilteredMultipleFilter, filteredZones)
|
||||||
assert.Equal(suite.T(), partitionResultResidualMultipleFilter, residualZones)
|
assert.Equal(suite.T(), partitionResultResidualMultipleFilter, residualZones)
|
||||||
|
|
||||||
// Check filtered, residual zones when a single child domain filter specified
|
|
||||||
filteredZones, residualZones = DomainFilterChildSingleClient.PartitionZones(zoneList)
|
|
||||||
assert.Equal(suite.T(), partitionResultFilteredSingleFilter, filteredZones)
|
|
||||||
assert.Equal(suite.T(), partitionResultResidualSingleFilter, residualZones)
|
|
||||||
|
|
||||||
// Check filter, residual zones when multiple child domain filters specified
|
|
||||||
filteredZones, residualZones = DomainFilterChildMultipleClient.PartitionZones(zoneList)
|
|
||||||
assert.Equal(suite.T(), partitionResultFilteredMultipleFilter, filteredZones)
|
|
||||||
assert.Equal(suite.T(), partitionResultResidualMultipleFilter, residualZones)
|
|
||||||
|
|
||||||
filteredZones, residualZones = RegexDomainFilterClient.PartitionZones(zoneList)
|
filteredZones, residualZones = RegexDomainFilterClient.PartitionZones(zoneList)
|
||||||
assert.Equal(suite.T(), partitionResultFilteredSingleFilter, filteredZones)
|
assert.Equal(suite.T(), partitionResultFilteredSingleFilter, filteredZones)
|
||||||
assert.Equal(suite.T(), partitionResultResidualSingleFilter, residualZones)
|
assert.Equal(suite.T(), partitionResultResidualSingleFilter, residualZones)
|
||||||
|
Loading…
Reference in New Issue
Block a user