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 4, 2020
1 parent e8b558d commit 11af9fa
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

- More errors context for AWS provider
- Fix: add serviceaccount name in kustomize deployment (#1689) @jmthvt
- Updates Oracle OCI SDK to latest (#1687) @ericrrath
- UltraDNS Provider (#1635) @kbhandari
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, aborting %s doRecords action: %v", 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, not applying changes: %v", 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 11af9fa

Please sign in to comment.