-
Notifications
You must be signed in to change notification settings - Fork 2.8k
provider/akamai: return early when there are no relevant changes #6189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -256,6 +256,12 @@ func (p AkamaiProvider) Records(context.Context) ([]*endpoint.Endpoint, error) { | |||||||||||||||
|
|
||||||||||||||||
| // ApplyChanges applies a given set of changes in a given zone. | ||||||||||||||||
| func (p AkamaiProvider) ApplyChanges(_ context.Context, changes *plan.Changes) error { | ||||||||||||||||
| // return early if there is nothing to change | ||||||||||||||||
| if len(changes.Create) == 0 && len(changes.Delete) == 0 && len(changes.UpdateNew) == 0 { | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and most likely log.Debug, not Info |
||||||||||||||||
| log.Info("All records are already up to date") | ||||||||||||||||
| return nil | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| zoneNameIDMapper := provider.ZoneIDName{} | ||||||||||||||||
| zones, err := p.fetchZones() | ||||||||||||||||
| if err != nil { | ||||||||||||||||
|
|
@@ -268,24 +274,35 @@ func (p AkamaiProvider) ApplyChanges(_ context.Context, changes *plan.Changes) e | |||||||||||||||
| } | ||||||||||||||||
| log.Debugf("Processing zones: [%v]", zoneNameIDMapper) | ||||||||||||||||
|
|
||||||||||||||||
| // Filter changes to only those matching managed zones | ||||||||||||||||
| filteredCreate := filterEndpointsByZone(zoneNameIDMapper, changes.Create) | ||||||||||||||||
| filteredDelete := filterEndpointsByZone(zoneNameIDMapper, changes.Delete) | ||||||||||||||||
| filteredUpdateNew := filterEndpointsByZone(zoneNameIDMapper, changes.UpdateNew) | ||||||||||||||||
|
|
||||||||||||||||
| // Return early if no changes match any managed zones | ||||||||||||||||
| if len(filteredCreate) == 0 && len(filteredDelete) == 0 && len(filteredUpdateNew) == 0 { | ||||||||||||||||
| log.Info("All records are already up to date, there are no changes for the matching hosted zones") | ||||||||||||||||
| return nil | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Create recordsets | ||||||||||||||||
| log.Debugf("Create Changes requested [%v]", changes.Create) | ||||||||||||||||
| if err := p.createRecordsets(zoneNameIDMapper, changes.Create); err != nil { | ||||||||||||||||
| log.Debugf("Create Changes requested [%v]", filteredCreate) | ||||||||||||||||
| if err := p.createRecordsets(zoneNameIDMapper, filteredCreate); err != nil { | ||||||||||||||||
| return err | ||||||||||||||||
| } | ||||||||||||||||
| // Delete recordsets | ||||||||||||||||
| log.Debugf("Delete Changes requested [%v]", changes.Delete) | ||||||||||||||||
| if err := p.deleteRecordsets(zoneNameIDMapper, changes.Delete); err != nil { | ||||||||||||||||
| log.Debugf("Delete Changes requested [%v]", filteredDelete) | ||||||||||||||||
| if err := p.deleteRecordsets(zoneNameIDMapper, filteredDelete); err != nil { | ||||||||||||||||
| return err | ||||||||||||||||
| } | ||||||||||||||||
| // Update recordsets | ||||||||||||||||
| log.Debugf("Update Changes requested [%v]", changes.UpdateNew) | ||||||||||||||||
| if err := p.updateNewRecordsets(zoneNameIDMapper, changes.UpdateNew); err != nil { | ||||||||||||||||
| log.Debugf("Update Changes requested [%v]", filteredUpdateNew) | ||||||||||||||||
| if err := p.updateNewRecordsets(zoneNameIDMapper, filteredUpdateNew); err != nil { | ||||||||||||||||
| return err | ||||||||||||||||
| } | ||||||||||||||||
| // Check that all old endpoints were accounted for | ||||||||||||||||
| revRecs := changes.Delete | ||||||||||||||||
| revRecs = append(revRecs, changes.UpdateNew...) | ||||||||||||||||
| revRecs := filteredDelete | ||||||||||||||||
| revRecs = append(revRecs, filteredUpdateNew...) | ||||||||||||||||
| for _, rec := range changes.UpdateOld { | ||||||||||||||||
| found := false | ||||||||||||||||
| for _, r := range revRecs { | ||||||||||||||||
|
|
@@ -484,3 +501,15 @@ func edgeChangesByZone(zoneMap provider.ZoneIDName, endpoints []*endpoint.Endpoi | |||||||||||||||
|
|
||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That eliminates the empty API calls at the source. Then filterEndpointsByZone and the second early return become unnecessary and can be removed. Still needs testing, could be that the unit tests are not right or smth. |
||||||||||||||||
| return createsByZone | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // filterEndpointsByZone returns only endpoints that match a zone in the mapper | ||||||||||||||||
| func filterEndpointsByZone(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) []*endpoint.Endpoint { | ||||||||||||||||
| filtered := make([]*endpoint.Endpoint, 0, len(endpoints)) | ||||||||||||||||
| for _, ep := range endpoints { | ||||||||||||||||
| zoneName, _ := zoneNameIDMapper.FindZone(ep.DNSName) | ||||||||||||||||
| if zoneName != "" { | ||||||||||||||||
| filtered = append(filtered, ep) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| return filtered | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.