Skip to content

Commit

Permalink
aws: errors with context
Browse files Browse the repository at this point in the history
When faced with errors from cloud providers (like "Throttling: Rate exceeded"), it's not always easy to find what operation caused the failure, and what action was aborted, if any,

Let's make it easier to identify an error source (and affected object when possible) by providing more context (and by using easy to find error messages).
  • Loading branch information
bpineau committed Aug 11, 2020
1 parent 3a61439 commit 83c2323
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- Improve errors context for AWS provider

## v0.7.3 - 2020-08-05

Expand Down
21 changes: 11 additions & 10 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/linki/instrumented_http"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"sigs.k8s.io/external-dns/endpoint"
Expand Down Expand Up @@ -166,7 +167,7 @@ func NewAWSProvider(awsConfig AWSConfig) (*AWSProvider, error) {
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to instantiate AWS session")
}

if awsConfig.AssumeRole != "" {
Expand Down Expand Up @@ -229,10 +230,10 @@ func (p *AWSProvider) Zones(ctx context.Context) (map[string]*route53.HostedZone

err := p.client.ListHostedZonesPagesWithContext(ctx, &route53.ListHostedZonesInput{}, f)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to list hosted zones")
}
if tagErr != nil {
return nil, tagErr
return nil, errors.Wrap(tagErr, "failed to list zones tags")
}

for _, zone := range zones {
Expand All @@ -255,7 +256,7 @@ func wildcardUnescape(s string) string {
func (p *AWSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoint, _ error) {
zones, err := p.Zones(ctx)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "records retrieval failed")
}

return p.records(ctx, zones)
Expand Down Expand Up @@ -339,7 +340,7 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*route53.Hos
}

if err := p.client.ListResourceRecordSetsPagesWithContext(ctx, params, f); err != nil {
return nil, err
return nil, errors.Wrapf(err, "failed to list resource records sets for zone %s", *z.Id)
}
}

Expand All @@ -364,12 +365,12 @@ func (p *AWSProvider) DeleteRecords(ctx context.Context, endpoints []*endpoint.E
func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []*endpoint.Endpoint) error {
zones, err := p.Zones(ctx)
if err != nil {
return err
return errors.Wrapf(err, "failed to list zones, aborting %s doRecords action", action)
}

records, err := p.records(ctx, zones)
if err != nil {
log.Errorf("getting records failed: %v", err)
log.Errorf("failed to list records while preparing %s doRecords action: %s", action, err)
}
return p.submitChanges(ctx, p.newChanges(action, endpoints, records, zones), zones)
}
Expand All @@ -378,15 +379,15 @@ func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []
func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
zones, err := p.Zones(ctx)
if err != nil {
return err
return errors.Wrap(err, "failed to list zones, not applying changes")
}

records, ok := ctx.Value(provider.RecordsContextKey).([]*endpoint.Endpoint)
if !ok {
var err error
records, err = p.records(ctx, zones)
if err != nil {
log.Errorf("getting records failed: %v", err)
log.Errorf("failed to get records while preparing to applying changes: %s", err)
}
}

Expand Down Expand Up @@ -581,7 +582,7 @@ func (p *AWSProvider) tagsForZone(ctx context.Context, zoneID string) (map[strin
ResourceId: aws.String(zoneID),
})
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "failed to list tags for zone %s", zoneID)
}
tagMap := map[string]string{}
for _, tag := range response.ResourceTagSet.Tags {
Expand Down

0 comments on commit 83c2323

Please sign in to comment.