Skip to content

Commit

Permalink
Merge pull request #3860 from johngmyers/refactor
Browse files Browse the repository at this point in the history
Remove DomainFilterInterface
  • Loading branch information
k8s-ci-robot authored Sep 1, 2023
2 parents c70e5f8 + e9be588 commit 0a6574a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
3 changes: 2 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ func (c *Controller) RunOnce(ctx context.Context) error {
verifiedARecords.Set(float64(vARecords))
verifiedAAAARecords.Set(float64(vAAAARecords))
endpoints = c.Registry.AdjustEndpoints(endpoints)
registryFilter := c.Registry.GetDomainFilter()

plan := &plan.Plan{
Policies: []plan.Policy{c.Policy},
Current: records,
Desired: endpoints,
DomainFilter: endpoint.MatchAllDomainFilters{c.DomainFilter, c.Registry.GetDomainFilter()},
DomainFilter: endpoint.MatchAllDomainFilters{&c.DomainFilter, &registryFilter},
ManagedRecords: c.ManagedRecordTypes,
}

Expand Down
7 changes: 1 addition & 6 deletions endpoint/domain_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ import (
"strings"
)

// DomainFilterInterface defines the interface to select matching domains for a specific provider or runtime
type DomainFilterInterface interface {
Match(domain string) bool
}

type MatchAllDomainFilters []DomainFilterInterface
type MatchAllDomainFilters []*DomainFilter

func (f MatchAllDomainFilters) Match(domain string) bool {
for _, filter := range f {
Expand Down
4 changes: 2 additions & 2 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Plan struct {
// Populated after calling Calculate()
Changes *Changes
// DomainFilter matches DNS names
DomainFilter endpoint.DomainFilterInterface
DomainFilter endpoint.MatchAllDomainFilters
// DNS record types that will be considered for management
ManagedRecords []string
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (p *Plan) shouldUpdateProviderSpecific(desired, current *endpoint.Endpoint)
// Per RFC 1034, CNAME records conflict with all other records - it is the
// only record with this property. The behavior of the planner may need to be
// made more sophisticated to codify this.
func filterRecordsForPlan(records []*endpoint.Endpoint, domainFilter endpoint.DomainFilterInterface, managedRecords []string) []*endpoint.Endpoint {
func filterRecordsForPlan(records []*endpoint.Endpoint, domainFilter endpoint.MatchAllDomainFilters, managedRecords []string) []*endpoint.Endpoint {
filtered := []*endpoint.Endpoint{}

for _, record := range records {
Expand Down
6 changes: 4 additions & 2 deletions plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,12 @@ func (suite *PlanTestSuite) TestDomainFiltersInitial() {
expectedUpdateNew := []*endpoint.Endpoint{}
expectedDelete := []*endpoint.Endpoint{}

domainFilter := endpoint.NewDomainFilterWithExclusions([]string{"domain.tld"}, []string{"ex.domain.tld"})
p := &Plan{
Policies: []Policy{&SyncPolicy{}},
Current: current,
Desired: desired,
DomainFilter: endpoint.NewDomainFilterWithExclusions([]string{"domain.tld"}, []string{"ex.domain.tld"}),
DomainFilter: endpoint.MatchAllDomainFilters{&domainFilter},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}

Expand All @@ -636,11 +637,12 @@ func (suite *PlanTestSuite) TestDomainFiltersUpdate() {
expectedUpdateNew := []*endpoint.Endpoint{}
expectedDelete := []*endpoint.Endpoint{}

domainFilter := endpoint.NewDomainFilterWithExclusions([]string{"domain.tld"}, []string{"ex.domain.tld"})
p := &Plan{
Policies: []Policy{&SyncPolicy{}},
Current: current,
Desired: desired,
DomainFilter: endpoint.NewDomainFilterWithExclusions([]string{"domain.tld"}, []string{"ex.domain.tld"}),
DomainFilter: endpoint.MatchAllDomainFilters{&domainFilter},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}

Expand Down
10 changes: 6 additions & 4 deletions provider/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ func AssertActions(t *testing.T, provider *CloudFlareProvider, endpoints []*endp
}

endpoints = provider.AdjustEndpoints(endpoints)

domainFilter := endpoint.NewDomainFilter([]string{"bar.com"})
plan := &plan.Plan{
Current: records,
Desired: endpoints,
DomainFilter: endpoint.NewDomainFilter([]string{"bar.com"}),
DomainFilter: endpoint.MatchAllDomainFilters{&domainFilter},
ManagedRecords: managedRecords,
}

Expand Down Expand Up @@ -1189,6 +1189,7 @@ func TestCloudflareComplexUpdate(t *testing.T) {
t.Errorf("should not fail, %s", err)
}

domainFilter := endpoint.NewDomainFilter([]string{"bar.com"})
plan := &plan.Plan{
Current: records,
Desired: provider.AdjustEndpoints([]*endpoint.Endpoint{
Expand All @@ -1206,7 +1207,7 @@ func TestCloudflareComplexUpdate(t *testing.T) {
},
},
}),
DomainFilter: endpoint.NewDomainFilter([]string{"bar.com"}),
DomainFilter: endpoint.MatchAllDomainFilters{&domainFilter},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}

Expand Down Expand Up @@ -1292,10 +1293,11 @@ func TestCustomTTLWithEnabledProxyNotChanged(t *testing.T) {

provider.AdjustEndpoints(endpoints)

domainFilter := endpoint.NewDomainFilter([]string{"bar.com"})
plan := &plan.Plan{
Current: records,
Desired: endpoints,
DomainFilter: endpoint.NewDomainFilter([]string{"bar.com"}),
DomainFilter: endpoint.MatchAllDomainFilters{&domainFilter},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}

Expand Down

0 comments on commit 0a6574a

Please sign in to comment.