Remove PropertyValuesEqual method from Provider interface

This commit is contained in:
John Gardiner Myers 2023-06-16 20:49:27 -07:00
parent 4fb2c7470a
commit 5affab0561
13 changed files with 48 additions and 165 deletions

View File

@ -217,12 +217,11 @@ func (c *Controller) RunOnce(ctx context.Context) error {
endpoints = c.Registry.AdjustEndpoints(endpoints) endpoints = c.Registry.AdjustEndpoints(endpoints)
plan := &plan.Plan{ plan := &plan.Plan{
Policies: []plan.Policy{c.Policy}, Policies: []plan.Policy{c.Policy},
Current: records, Current: records,
Desired: endpoints, Desired: endpoints,
DomainFilter: endpoint.MatchAllDomainFilters{c.DomainFilter, c.Registry.GetDomainFilter()}, DomainFilter: endpoint.MatchAllDomainFilters{c.DomainFilter, c.Registry.GetDomainFilter()},
PropertyComparator: c.Registry.PropertyValuesEqual, ManagedRecords: c.ManagedRecordTypes,
ManagedRecords: c.ManagedRecordTypes,
} }
plan = plan.Calculate() plan = plan.Calculate()

View File

@ -44,8 +44,6 @@ type Plan struct {
Changes *Changes Changes *Changes
// DomainFilter matches DNS names // DomainFilter matches DNS names
DomainFilter endpoint.DomainFilterInterface DomainFilter endpoint.DomainFilterInterface
// Property comparator compares custom properties of providers
PropertyComparator PropertyComparator
// DNS record types that will be considered for management // DNS record types that will be considered for management
ManagedRecords []string ManagedRecords []string
} }
@ -217,21 +215,9 @@ func (p *Plan) shouldUpdateProviderSpecific(desired, current *endpoint.Endpoint)
if current.ProviderSpecific != nil { if current.ProviderSpecific != nil {
for _, c := range current.ProviderSpecific { for _, c := range current.ProviderSpecific {
if d, ok := desiredProperties[c.Name]; ok { if d, ok := desiredProperties[c.Name]; ok {
if p.PropertyComparator != nil { return c.Value != d.Value
if !p.PropertyComparator(c.Name, c.Value, d.Value) {
return true
}
} else if c.Value != d.Value {
return true
}
} else { } else {
if p.PropertyComparator != nil { return c.Value != ""
if !p.PropertyComparator(c.Name, c.Value, "") {
return true
}
} else if c.Value != "" {
return true
}
} }
} }
} }

View File

@ -342,21 +342,18 @@ func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificChange() {
validateEntries(suite.T(), changes.Delete, expectedDelete) validateEntries(suite.T(), changes.Delete, expectedDelete)
} }
func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificDefaultFalse() { func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificRemoval() {
current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificFalse} current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificFalse}
desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset} desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
expectedCreate := []*endpoint.Endpoint{} expectedCreate := []*endpoint.Endpoint{}
expectedUpdateOld := []*endpoint.Endpoint{} expectedUpdateOld := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificFalse}
expectedUpdateNew := []*endpoint.Endpoint{} expectedUpdateNew := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
expectedDelete := []*endpoint.Endpoint{} expectedDelete := []*endpoint.Endpoint{}
p := &Plan{ p := &Plan{
Policies: []Policy{&SyncPolicy{}}, Policies: []Policy{&SyncPolicy{}},
Current: current, Current: current,
Desired: desired, Desired: desired,
PropertyComparator: func(name, previous, current string) bool {
return CompareBoolean(false, name, previous, current)
},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME}, ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
} }
@ -367,29 +364,28 @@ func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificDefaultFalse(
validateEntries(suite.T(), changes.Delete, expectedDelete) validateEntries(suite.T(), changes.Delete, expectedDelete)
} }
func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificDefualtTrue() { // todo: this is currently an expect-fail
current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue} //func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificAddition() {
desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset} // current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
expectedCreate := []*endpoint.Endpoint{} // desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
expectedUpdateOld := []*endpoint.Endpoint{} // expectedCreate := []*endpoint.Endpoint{}
expectedUpdateNew := []*endpoint.Endpoint{} // expectedUpdateOld := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
expectedDelete := []*endpoint.Endpoint{} // expectedUpdateNew := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
// expectedDelete := []*endpoint.Endpoint{}
p := &Plan{ //
Policies: []Policy{&SyncPolicy{}}, // p := &Plan{
Current: current, // Policies: []Policy{&SyncPolicy{}},
Desired: desired, // Current: current,
PropertyComparator: func(name, previous, current string) bool { // Desired: desired,
return CompareBoolean(true, name, previous, current) // ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}, // }
} //
// changes := p.Calculate().Changes
changes := p.Calculate().Changes // validateEntries(suite.T(), changes.Create, expectedCreate)
validateEntries(suite.T(), changes.Create, expectedCreate) // validateEntries(suite.T(), changes.UpdateNew, expectedUpdateNew)
validateEntries(suite.T(), changes.UpdateNew, expectedUpdateNew) // validateEntries(suite.T(), changes.UpdateOld, expectedUpdateOld)
validateEntries(suite.T(), changes.UpdateOld, expectedUpdateOld) // validateEntries(suite.T(), changes.Delete, expectedDelete)
validateEntries(suite.T(), changes.Delete, expectedDelete) //}
}
func (suite *PlanTestSuite) TestSyncSecondRoundWithOwnerInherited() { func (suite *PlanTestSuite) TestSyncSecondRoundWithOwnerInherited() {
current := []*endpoint.Endpoint{suite.fooV1Cname} current := []*endpoint.Endpoint{suite.fooV1Cname}
@ -744,15 +740,11 @@ func TestNormalizeDNSName(t *testing.T) {
} }
func TestShouldUpdateProviderSpecific(tt *testing.T) { func TestShouldUpdateProviderSpecific(tt *testing.T) {
comparator := func(name, previous, current string) bool {
return previous == current
}
for _, test := range []struct { for _, test := range []struct {
name string name string
current *endpoint.Endpoint current *endpoint.Endpoint
desired *endpoint.Endpoint desired *endpoint.Endpoint
propertyComparator func(name, previous, current string) bool shouldUpdate bool
shouldUpdate bool
}{ }{
{ {
name: "skip AWS target health", name: "skip AWS target health",
@ -768,8 +760,7 @@ func TestShouldUpdateProviderSpecific(tt *testing.T) {
{Name: "aws/evaluate-target-health", Value: "true"}, {Name: "aws/evaluate-target-health", Value: "true"},
}, },
}, },
propertyComparator: comparator, shouldUpdate: false,
shouldUpdate: false,
}, },
{ {
name: "custom property unchanged", name: "custom property unchanged",
@ -783,8 +774,7 @@ func TestShouldUpdateProviderSpecific(tt *testing.T) {
{Name: "custom/property", Value: "true"}, {Name: "custom/property", Value: "true"},
}, },
}, },
propertyComparator: comparator, shouldUpdate: false,
shouldUpdate: false,
}, },
{ {
name: "custom property value changed", name: "custom property value changed",
@ -798,54 +788,10 @@ func TestShouldUpdateProviderSpecific(tt *testing.T) {
{Name: "custom/property", Value: "false"}, {Name: "custom/property", Value: "false"},
}, },
}, },
propertyComparator: comparator,
shouldUpdate: true,
},
{
name: "custom property key changed",
current: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "true"},
},
},
desired: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "new/property", Value: "true"},
},
},
propertyComparator: comparator,
shouldUpdate: true,
},
{
name: "desired has same key and value as current but not comparator is set",
current: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "true"},
},
},
desired: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "true"},
},
},
shouldUpdate: false,
},
{
name: "desired has same key and different value as current but not comparator is set",
current: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "true"},
},
},
desired: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "false"},
},
},
shouldUpdate: true, shouldUpdate: true,
}, },
{ {
name: "desired has different key from current but not comparator is set", name: "custom property key changed",
current: &endpoint.Endpoint{ current: &endpoint.Endpoint{
ProviderSpecific: []endpoint.ProviderSpecificProperty{ ProviderSpecific: []endpoint.ProviderSpecificProperty{
{Name: "custom/property", Value: "true"}, {Name: "custom/property", Value: "true"},
@ -861,10 +807,9 @@ func TestShouldUpdateProviderSpecific(tt *testing.T) {
} { } {
tt.Run(test.name, func(t *testing.T) { tt.Run(test.name, func(t *testing.T) {
plan := &Plan{ plan := &Plan{
Current: []*endpoint.Endpoint{test.current}, Current: []*endpoint.Endpoint{test.current},
Desired: []*endpoint.Endpoint{test.desired}, Desired: []*endpoint.Endpoint{test.desired},
PropertyComparator: test.propertyComparator, ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
} }
b := plan.shouldUpdateProviderSpecific(test.desired, test.current) b := plan.shouldUpdateProviderSpecific(test.desired, test.current)
assert.Equal(t, test.shouldUpdate, b) assert.Equal(t, test.shouldUpdate, b)

View File

@ -1150,10 +1150,9 @@ func TestProviderPropertiesIdempotency(t *testing.T) {
desired = provider.AdjustEndpoints(desired) desired = provider.AdjustEndpoints(desired)
plan := plan.Plan{ plan := plan.Plan{
Current: current, Current: current,
Desired: desired, Desired: desired,
PropertyComparator: provider.PropertyValuesEqual, ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
} }
plan = *plan.Calculate() plan = *plan.Calculate()

View File

@ -340,14 +340,6 @@ func (p designateProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, e
return result, nil return result, nil
} }
func (p designateProvider) PropertyValuesEqual(name, previous, current string) bool {
if name == designateRecordSetID || name == designateZoneID || name == designateOriginalRecords {
return true
}
return previous == current
}
// temporary structure to hold recordset parameters so that we could aggregate endpoints into recordsets // temporary structure to hold recordset parameters so that we could aggregate endpoints into recordsets
type recordSet struct { type recordSet struct {
dnsName string dnsName string

View File

@ -83,10 +83,6 @@ func (p *PluralProvider) Records(_ context.Context) (endpoints []*endpoint.Endpo
return return
} }
func (p *PluralProvider) PropertyValuesEqual(name, previous, current string) bool {
return p.BaseProvider.PropertyValuesEqual(name, previous, current)
}
func (p *PluralProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { func (p *PluralProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
return endpoints return endpoints
} }

View File

@ -29,7 +29,6 @@ import (
type Provider interface { type Provider interface {
Records(ctx context.Context) ([]*endpoint.Endpoint, error) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
ApplyChanges(ctx context.Context, changes *plan.Changes) error ApplyChanges(ctx context.Context, changes *plan.Changes) error
PropertyValuesEqual(name string, previous string, current string) bool
// AdjustEndpoints canonicalizes a set of candidate endpoints. // AdjustEndpoints canonicalizes a set of candidate endpoints.
// It is called with a set of candidate endpoints obtained from the various sources. // It is called with a set of candidate endpoints obtained from the various sources.
// It returns a set modified as required by the provider. The provider is responsible for // It returns a set modified as required by the provider. The provider is responsible for
@ -47,10 +46,6 @@ func (b BaseProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoin
return endpoints return endpoints
} }
func (b BaseProvider) PropertyValuesEqual(name, previous, current string) bool {
return previous == current
}
func (b BaseProvider) GetDomainFilter() endpoint.DomainFilter { func (b BaseProvider) GetDomainFilter() endpoint.DomainFilter {
return endpoint.DomainFilter{} return endpoint.DomainFilter{}
} }

View File

@ -54,12 +54,3 @@ func TestDifference(t *testing.T) {
assert.Equal(t, remove, []string{"foo"}) assert.Equal(t, remove, []string{"foo"})
assert.Equal(t, leave, []string{"bar"}) assert.Equal(t, leave, []string{"bar"})
} }
func TestBaseProviderPropertyEquality(t *testing.T) {
p := BaseProvider{}
assert.True(t, p.PropertyValuesEqual("some.property", "", ""), "Both properties not present")
assert.False(t, p.PropertyValuesEqual("some.property", "", "Foo"), "First property missing")
assert.False(t, p.PropertyValuesEqual("some.property", "Foo", ""), "Second property missing")
assert.True(t, p.PropertyValuesEqual("some.property", "Foo", "Foo"), "Properties the same")
assert.False(t, p.PropertyValuesEqual("some.property", "Foo", "Bar"), "Attributes differ")
}

View File

@ -95,10 +95,6 @@ func (sdr *AWSSDRegistry) updateLabels(endpoints []*endpoint.Endpoint) {
} }
} }
func (sdr *AWSSDRegistry) PropertyValuesEqual(name string, previous string, current string) bool {
return sdr.provider.PropertyValuesEqual(name, previous, current)
}
// AdjustEndpoints modifies the endpoints as needed by the specific provider // AdjustEndpoints modifies the endpoints as needed by the specific provider
func (sdr *AWSSDRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { func (sdr *AWSSDRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
return sdr.provider.AdjustEndpoints(endpoints) return sdr.provider.AdjustEndpoints(endpoints)

View File

@ -248,11 +248,6 @@ func (im *DynamoDBRegistry) ApplyChanges(ctx context.Context, changes *plan.Chan
}) })
} }
// PropertyValuesEqual compares two attribute values for equality.
func (im *DynamoDBRegistry) PropertyValuesEqual(name string, previous string, current string) bool {
return im.provider.PropertyValuesEqual(name, previous, current)
}
// AdjustEndpoints modifies the endpoints as needed by the specific provider. // AdjustEndpoints modifies the endpoints as needed by the specific provider.
func (im *DynamoDBRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { func (im *DynamoDBRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
return im.provider.AdjustEndpoints(endpoints) return im.provider.AdjustEndpoints(endpoints)

View File

@ -50,11 +50,6 @@ func (im *NoopRegistry) ApplyChanges(ctx context.Context, changes *plan.Changes)
return im.provider.ApplyChanges(ctx, changes) return im.provider.ApplyChanges(ctx, changes)
} }
// PropertyValuesEqual compares two property values for equality
func (im *NoopRegistry) PropertyValuesEqual(attribute string, previous string, current string) bool {
return im.provider.PropertyValuesEqual(attribute, previous, current)
}
// AdjustEndpoints modifies the endpoints as needed by the specific provider // AdjustEndpoints modifies the endpoints as needed by the specific provider
func (im *NoopRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { func (im *NoopRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
return im.provider.AdjustEndpoints(endpoints) return im.provider.AdjustEndpoints(endpoints)

View File

@ -32,7 +32,6 @@ import (
type Registry interface { type Registry interface {
Records(ctx context.Context) ([]*endpoint.Endpoint, error) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
ApplyChanges(ctx context.Context, changes *plan.Changes) error ApplyChanges(ctx context.Context, changes *plan.Changes) error
PropertyValuesEqual(attribute string, previous string, current string) bool
AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint
GetDomainFilter() endpoint.DomainFilter GetDomainFilter() endpoint.DomainFilter
} }

View File

@ -284,11 +284,6 @@ func (im *TXTRegistry) ApplyChanges(ctx context.Context, changes *plan.Changes)
return im.provider.ApplyChanges(ctx, filteredChanges) return im.provider.ApplyChanges(ctx, filteredChanges)
} }
// PropertyValuesEqual compares two attribute values for equality
func (im *TXTRegistry) PropertyValuesEqual(name string, previous string, current string) bool {
return im.provider.PropertyValuesEqual(name, previous, current)
}
// AdjustEndpoints modifies the endpoints as needed by the specific provider // AdjustEndpoints modifies the endpoints as needed by the specific provider
func (im *TXTRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { func (im *TXTRegistry) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
return im.provider.AdjustEndpoints(endpoints) return im.provider.AdjustEndpoints(endpoints)