chore(provider/aws): reduce if-nesting, dryRun (#5688)

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
Ivan Ka 2025-07-29 11:10:02 +01:00 committed by GitHub
parent fe7940ce0a
commit b741f3103c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -734,56 +734,59 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes Route53Changes,
log.Infof("Desired change: %s %s %s", c.Action, *c.ResourceRecordSet.Name, c.ResourceRecordSet.Type) log.Infof("Desired change: %s %s %s", c.Action, *c.ResourceRecordSet.Name, c.ResourceRecordSet.Type)
} }
if !p.dryRun { if p.dryRun {
params := &route53.ChangeResourceRecordSetsInput{ log.Debug("Dry run mode, skipping change submission")
HostedZoneId: aws.String(z), continue
ChangeBatch: &route53types.ChangeBatch{ }
Changes: b.Route53Changes(),
},
}
successfulChanges := 0 params := &route53.ChangeResourceRecordSetsInput{
HostedZoneId: aws.String(z),
ChangeBatch: &route53types.ChangeBatch{
Changes: b.Route53Changes(),
},
}
client := p.clients[zones[z].profile] successfulChanges := 0
if _, err := client.ChangeResourceRecordSets(ctx, params); err != nil {
log.Errorf("Failure in zone %s when submitting change batch: %v", *zones[z].zone.Name, err)
changesByOwnership := groupChangesByNameAndOwnershipRelation(b) client := p.clients[zones[z].profile]
if _, err := client.ChangeResourceRecordSets(ctx, params); err != nil {
log.Errorf("Failure in zone %s when submitting change batch: %v", *zones[z].zone.Name, err)
if len(changesByOwnership) > 1 { changesByOwnership := groupChangesByNameAndOwnershipRelation(b)
log.Debug("Trying to submit change sets one-by-one instead")
for _, changes := range changesByOwnership { if len(changesByOwnership) > 1 {
if log.Logger.IsLevelEnabled(debugLevel) { log.Debug("Trying to submit change sets one-by-one instead")
for _, c := range changes { for _, changes := range changesByOwnership {
log.Debugf("Desired change: %s %s %s", c.Action, *c.ResourceRecordSet.Name, c.ResourceRecordSet.Type) if log.Logger.IsLevelEnabled(debugLevel) {
} for _, c := range changes {
} log.Debugf("Desired change: %s %s %s", c.Action, *c.ResourceRecordSet.Name, c.ResourceRecordSet.Type)
params.ChangeBatch = &route53types.ChangeBatch{
Changes: changes.Route53Changes(),
}
if _, err := client.ChangeResourceRecordSets(ctx, params); err != nil {
failedUpdate = true
log.Errorf("Failed submitting change (error: %v), it will be retried in a separate change batch in the next iteration", err)
p.failedChangesQueue[z] = append(p.failedChangesQueue[z], changes...)
} else {
successfulChanges = successfulChanges + len(changes)
} }
} }
} else { params.ChangeBatch = &route53types.ChangeBatch{
failedUpdate = true Changes: changes.Route53Changes(),
}
if _, err := client.ChangeResourceRecordSets(ctx, params); err != nil {
failedUpdate = true
log.Errorf("Failed submitting change (error: %v), it will be retried in a separate change batch in the next iteration", err)
p.failedChangesQueue[z] = append(p.failedChangesQueue[z], changes...)
} else {
successfulChanges = successfulChanges + len(changes)
}
} }
} else { } else {
successfulChanges = len(b) failedUpdate = true
} }
} else {
successfulChanges = len(b)
}
if successfulChanges > 0 { if successfulChanges > 0 {
// z is the R53 Hosted Zone ID already as aws.StringValue // z is the R53 Hosted Zone ID already as aws.StringValue
log.Infof("%d record(s) were successfully updated", successfulChanges) log.Infof("%d record(s) were successfully updated", successfulChanges)
} }
if i != len(batchCs)-1 { if i != len(batchCs)-1 {
time.Sleep(p.batchChangeInterval) time.Sleep(p.batchChangeInterval)
}
} }
} }