Skip to content

Commit

Permalink
Merge pull request #3863 from johngmyers/add-providerspecific
Browse files Browse the repository at this point in the history
Fix reconciliation of provider-specific properties
  • Loading branch information
k8s-ci-robot authored Aug 12, 2023
2 parents b420a32 + 5339c0c commit ffcf669
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
21 changes: 10 additions & 11 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,21 @@ func shouldUpdateTTL(desired, current *endpoint.Endpoint) bool {
func (p *Plan) shouldUpdateProviderSpecific(desired, current *endpoint.Endpoint) bool {
desiredProperties := map[string]endpoint.ProviderSpecificProperty{}

if desired.ProviderSpecific != nil {
for _, d := range desired.ProviderSpecific {
desiredProperties[d.Name] = d
}
for _, d := range desired.ProviderSpecific {
desiredProperties[d.Name] = d
}
if current.ProviderSpecific != nil {
for _, c := range current.ProviderSpecific {
if d, ok := desiredProperties[c.Name]; ok {
return c.Value != d.Value
} else {
return c.Value != ""
for _, c := range current.ProviderSpecific {
if d, ok := desiredProperties[c.Name]; ok {
if c.Value != d.Value {
return true
}
delete(desiredProperties, c.Name)
} else {
return true
}
}

return false
return len(desiredProperties) > 0
}

// filterRecordsForPlan removes records that are not relevant to the planner.
Expand Down
58 changes: 35 additions & 23 deletions plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (suite *PlanTestSuite) SetupTest() {
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
ProviderSpecific: endpoint.ProviderSpecific{
endpoint.ProviderSpecificProperty{
Name: "alias",
Value: "false",
},
endpoint.ProviderSpecificProperty{
Name: "external-dns.alpha.kubernetes.io/cloudflare-proxied",
Value: "true",
Expand All @@ -173,6 +177,10 @@ func (suite *PlanTestSuite) SetupTest() {
Name: "external-dns.alpha.kubernetes.io/cloudflare-proxied",
Value: "false",
},
endpoint.ProviderSpecificProperty{
Name: "alias",
Value: "false",
},
},
}
suite.bar127AWithProviderSpecificUnset = &endpoint.Endpoint{
Expand All @@ -182,7 +190,12 @@ func (suite *PlanTestSuite) SetupTest() {
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
ProviderSpecific: endpoint.ProviderSpecific{},
ProviderSpecific: endpoint.ProviderSpecific{
endpoint.ProviderSpecificProperty{
Name: "alias",
Value: "false",
},
},
}
suite.bar192A = &endpoint.Endpoint{
DNSName: "bar",
Expand Down Expand Up @@ -364,28 +377,27 @@ func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificRemoval() {
validateEntries(suite.T(), changes.Delete, expectedDelete)
}

// todo: this is currently an expect-fail
//func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificAddition() {
// current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
// desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
// expectedCreate := []*endpoint.Endpoint{}
// expectedUpdateOld := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
// expectedUpdateNew := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
// expectedDelete := []*endpoint.Endpoint{}
//
// p := &Plan{
// Policies: []Policy{&SyncPolicy{}},
// Current: current,
// Desired: desired,
// ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
// }
//
// changes := p.Calculate().Changes
// validateEntries(suite.T(), changes.Create, expectedCreate)
// validateEntries(suite.T(), changes.UpdateNew, expectedUpdateNew)
// validateEntries(suite.T(), changes.UpdateOld, expectedUpdateOld)
// validateEntries(suite.T(), changes.Delete, expectedDelete)
//}
func (suite *PlanTestSuite) TestSyncSecondRoundWithProviderSpecificAddition() {
current := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
desired := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
expectedCreate := []*endpoint.Endpoint{}
expectedUpdateOld := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificUnset}
expectedUpdateNew := []*endpoint.Endpoint{suite.bar127AWithProviderSpecificTrue}
expectedDelete := []*endpoint.Endpoint{}

p := &Plan{
Policies: []Policy{&SyncPolicy{}},
Current: current,
Desired: desired,
ManagedRecords: []string{endpoint.RecordTypeA, endpoint.RecordTypeCNAME},
}

changes := p.Calculate().Changes
validateEntries(suite.T(), changes.Create, expectedCreate)
validateEntries(suite.T(), changes.UpdateNew, expectedUpdateNew)
validateEntries(suite.T(), changes.UpdateOld, expectedUpdateOld)
validateEntries(suite.T(), changes.Delete, expectedDelete)
}

func (suite *PlanTestSuite) TestSyncSecondRoundWithOwnerInherited() {
current := []*endpoint.Endpoint{suite.fooV1Cname}
Expand Down

0 comments on commit ffcf669

Please sign in to comment.