mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
remove unused parameters in aws change submit method
This commit is contained in:
parent
8cc952298c
commit
1aef05c8e5
@ -414,14 +414,9 @@ func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []
|
|||||||
return errors.Wrapf(err, "failed to list zones, aborting %s doRecords action", action)
|
return errors.Wrapf(err, "failed to list zones, aborting %s doRecords action", action)
|
||||||
}
|
}
|
||||||
|
|
||||||
records, err := p.records(ctx, zones)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to list records while preparing %s doRecords action: %s", action, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
p.AdjustEndpoints(endpoints)
|
p.AdjustEndpoints(endpoints)
|
||||||
|
|
||||||
return p.submitChanges(ctx, p.newChanges(action, endpoints, records, zones), zones)
|
return p.submitChanges(ctx, p.newChanges(action, endpoints), zones)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRecords updates a given set of old records to a new set of records in a given hosted zone.
|
// UpdateRecords updates a given set of old records to a new set of records in a given hosted zone.
|
||||||
@ -431,15 +426,10 @@ func (p *AWSProvider) UpdateRecords(ctx context.Context, updates, current []*end
|
|||||||
return errors.Wrapf(err, "failed to list zones, aborting UpdateRecords")
|
return errors.Wrapf(err, "failed to list zones, aborting UpdateRecords")
|
||||||
}
|
}
|
||||||
|
|
||||||
records, err := p.records(ctx, zones)
|
return p.submitChanges(ctx, p.createUpdateChanges(updates, current), zones)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to list records while preparing UpdateRecords: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.submitChanges(ctx, p.createUpdateChanges(updates, current, records, zones), zones)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint.Endpoint, recordsCache []*endpoint.Endpoint, zones map[string]*route53.HostedZone) []*route53.Change {
|
func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint.Endpoint) []*route53.Change {
|
||||||
var deletes []*endpoint.Endpoint
|
var deletes []*endpoint.Endpoint
|
||||||
var creates []*endpoint.Endpoint
|
var creates []*endpoint.Endpoint
|
||||||
var updates []*endpoint.Endpoint
|
var updates []*endpoint.Endpoint
|
||||||
@ -459,9 +449,9 @@ func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint
|
|||||||
}
|
}
|
||||||
|
|
||||||
combined := make([]*route53.Change, 0, len(deletes)+len(creates)+len(updates))
|
combined := make([]*route53.Change, 0, len(deletes)+len(creates)+len(updates))
|
||||||
combined = append(combined, p.newChanges(route53.ChangeActionCreate, creates, recordsCache, zones)...)
|
combined = append(combined, p.newChanges(route53.ChangeActionCreate, creates)...)
|
||||||
combined = append(combined, p.newChanges(route53.ChangeActionUpsert, updates, recordsCache, zones)...)
|
combined = append(combined, p.newChanges(route53.ChangeActionUpsert, updates)...)
|
||||||
combined = append(combined, p.newChanges(route53.ChangeActionDelete, deletes, recordsCache, zones)...)
|
combined = append(combined, p.newChanges(route53.ChangeActionDelete, deletes)...)
|
||||||
return combined
|
return combined
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,20 +477,11 @@ func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
|
|||||||
return errors.Wrap(err, "failed to list zones, not applying changes")
|
return errors.Wrap(err, "failed to list zones, not applying changes")
|
||||||
}
|
}
|
||||||
|
|
||||||
records, ok := ctx.Value(provider.RecordsContextKey).([]*endpoint.Endpoint)
|
updateChanges := p.createUpdateChanges(changes.UpdateNew, changes.UpdateOld)
|
||||||
if !ok {
|
|
||||||
var err error
|
|
||||||
records, err = p.records(ctx, zones)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to get records while preparing to applying changes: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateChanges := p.createUpdateChanges(changes.UpdateNew, changes.UpdateOld, records, zones)
|
|
||||||
|
|
||||||
combinedChanges := make([]*route53.Change, 0, len(changes.Delete)+len(changes.Create)+len(updateChanges))
|
combinedChanges := make([]*route53.Change, 0, len(changes.Delete)+len(changes.Create)+len(updateChanges))
|
||||||
combinedChanges = append(combinedChanges, p.newChanges(route53.ChangeActionCreate, changes.Create, records, zones)...)
|
combinedChanges = append(combinedChanges, p.newChanges(route53.ChangeActionCreate, changes.Create)...)
|
||||||
combinedChanges = append(combinedChanges, p.newChanges(route53.ChangeActionDelete, changes.Delete, records, zones)...)
|
combinedChanges = append(combinedChanges, p.newChanges(route53.ChangeActionDelete, changes.Delete)...)
|
||||||
combinedChanges = append(combinedChanges, updateChanges...)
|
combinedChanges = append(combinedChanges, updateChanges...)
|
||||||
|
|
||||||
return p.submitChanges(ctx, combinedChanges, zones)
|
return p.submitChanges(ctx, combinedChanges, zones)
|
||||||
@ -567,11 +548,11 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newChanges returns a collection of Changes based on the given records and action.
|
// newChanges returns a collection of Changes based on the given records and action.
|
||||||
func (p *AWSProvider) newChanges(action string, endpoints []*endpoint.Endpoint, recordsCache []*endpoint.Endpoint, zones map[string]*route53.HostedZone) []*route53.Change {
|
func (p *AWSProvider) newChanges(action string, endpoints []*endpoint.Endpoint) []*route53.Change {
|
||||||
changes := make([]*route53.Change, 0, len(endpoints))
|
changes := make([]*route53.Change, 0, len(endpoints))
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
change, dualstack := p.newChange(action, endpoint, recordsCache, zones)
|
change, dualstack := p.newChange(action, endpoint)
|
||||||
changes = append(changes, change)
|
changes = append(changes, change)
|
||||||
if dualstack {
|
if dualstack {
|
||||||
// make a copy of change, modify RRS type to AAAA, then add new change
|
// make a copy of change, modify RRS type to AAAA, then add new change
|
||||||
@ -619,7 +600,7 @@ func (p *AWSProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoin
|
|||||||
// returned Change is based on the given record by the given action, e.g.
|
// returned Change is based on the given record by the given action, e.g.
|
||||||
// action=ChangeActionCreate returns a change for creation of the record and
|
// action=ChangeActionCreate returns a change for creation of the record and
|
||||||
// action=ChangeActionDelete returns a change for deletion of the record.
|
// action=ChangeActionDelete returns a change for deletion of the record.
|
||||||
func (p *AWSProvider) newChange(action string, ep *endpoint.Endpoint, recordsCache []*endpoint.Endpoint, zones map[string]*route53.HostedZone) (*route53.Change, bool) {
|
func (p *AWSProvider) newChange(action string, ep *endpoint.Endpoint) (*route53.Change, bool) {
|
||||||
change := &route53.Change{
|
change := &route53.Change{
|
||||||
Action: aws.String(action),
|
Action: aws.String(action),
|
||||||
ResourceRecordSet: &route53.ResourceRecordSet{
|
ResourceRecordSet: &route53.ResourceRecordSet{
|
||||||
|
@ -501,7 +501,7 @@ func TestAWSApplyChanges(t *testing.T) {
|
|||||||
setup func(p *AWSProvider) context.Context
|
setup func(p *AWSProvider) context.Context
|
||||||
listRRSets int
|
listRRSets int
|
||||||
}{
|
}{
|
||||||
{"no cache", func(p *AWSProvider) context.Context { return context.Background() }, 3},
|
{"no cache", func(p *AWSProvider) context.Context { return context.Background() }, 0},
|
||||||
{"cached", func(p *AWSProvider) context.Context {
|
{"cached", func(p *AWSProvider) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
records, err := p.Records(ctx)
|
records, err := p.Records(ctx)
|
||||||
@ -781,7 +781,7 @@ func TestAWSsubmitChanges(t *testing.T) {
|
|||||||
zones, _ := provider.Zones(ctx)
|
zones, _ := provider.Zones(ctx)
|
||||||
records, _ := provider.Records(ctx)
|
records, _ := provider.Records(ctx)
|
||||||
cs := make([]*route53.Change, 0, len(endpoints))
|
cs := make([]*route53.Change, 0, len(endpoints))
|
||||||
cs = append(cs, provider.newChanges(route53.ChangeActionCreate, endpoints, records, zones)...)
|
cs = append(cs, provider.newChanges(route53.ChangeActionCreate, endpoints)...)
|
||||||
|
|
||||||
require.NoError(t, provider.submitChanges(ctx, cs, zones))
|
require.NoError(t, provider.submitChanges(ctx, cs, zones))
|
||||||
|
|
||||||
@ -798,11 +798,9 @@ func TestAWSsubmitChangesError(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
zones, err := provider.Zones(ctx)
|
zones, err := provider.Zones(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
records, err := provider.Records(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
ep := endpoint.NewEndpointWithTTL("fail.zone-1.ext-dns-test-2.teapot.zalan.do", endpoint.RecordTypeA, endpoint.TTL(recordTTL), "1.0.0.1")
|
ep := endpoint.NewEndpointWithTTL("fail.zone-1.ext-dns-test-2.teapot.zalan.do", endpoint.RecordTypeA, endpoint.TTL(recordTTL), "1.0.0.1")
|
||||||
cs := provider.newChanges(route53.ChangeActionCreate, []*endpoint.Endpoint{ep}, records, zones)
|
cs := provider.newChanges(route53.ChangeActionCreate, []*endpoint.Endpoint{ep})
|
||||||
|
|
||||||
require.Error(t, provider.submitChanges(ctx, cs, zones))
|
require.Error(t, provider.submitChanges(ctx, cs, zones))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user