diff --git a/controller/controller.go b/controller/controller.go index 63ae9f6240..a3ef2e8b23 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + "errors" "fmt" "sync" "time" @@ -331,7 +332,11 @@ func (c *Controller) Run(ctx context.Context) { for { if c.ShouldRunOnce(time.Now()) { if err := c.RunOnce(ctx); err != nil { - log.Fatal(err) + if errors.Is(err, provider.SoftError) { + log.Errorf("Failed to do run once: %v", err) + } else { + log.Fatalf("Failed to do run once: %v", err) + } } } select { diff --git a/provider/aws/aws.go b/provider/aws/aws.go index fd16a6d1ac..6b1690f3c5 100644 --- a/provider/aws/aws.go +++ b/provider/aws/aws.go @@ -27,7 +27,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/service/route53" - "github.com/pkg/errors" log "github.com/sirupsen/logrus" "sigs.k8s.io/external-dns/endpoint" @@ -325,10 +324,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, errors.Wrap(err, "failed to list hosted zones") + return nil, provider.NewSoftError(fmt.Errorf("failed to list hosted zones: %w", err)) } if tagErr != nil { - return nil, errors.Wrap(tagErr, "failed to list zones tags") + return nil, provider.NewSoftError(fmt.Errorf("failed to list zones tags: %w", tagErr)) } for _, zone := range zones { @@ -353,7 +352,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, errors.Wrap(err, "records retrieval failed") + return nil, provider.NewSoftError(fmt.Errorf("records retrieval failed: %w", err)) } return p.records(ctx, zones) @@ -445,7 +444,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, errors.Wrapf(err, "failed to list resource records sets for zone %s", *z.Id) + return nil, provider.NewSoftError(fmt.Errorf("failed to list resource records sets for zone %s: %w", *z.Id, err)) } } @@ -530,7 +529,7 @@ func (p *AWSProvider) GetDomainFilter() endpoint.DomainFilter { func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error { zones, err := p.Zones(ctx) if err != nil { - return errors.Wrap(err, "failed to list zones, not applying changes") + return provider.NewSoftError(fmt.Errorf("failed to list zones, not applying changes: %w", err)) } updateChanges := p.createUpdateChanges(changes.UpdateNew, changes.UpdateOld) @@ -632,7 +631,7 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes Route53Changes, } if len(failedZones) > 0 { - return errors.Errorf("failed to submit all changes for the following zones: %v", failedZones) + return provider.NewSoftError(fmt.Errorf("failed to submit all changes for the following zones: %v", failedZones)) } return nil @@ -847,7 +846,7 @@ func (p *AWSProvider) tagsForZone(ctx context.Context, zoneID string) (map[strin ResourceId: aws.String(zoneID), }) if err != nil { - return nil, errors.Wrapf(err, "failed to list tags for zone %s", zoneID) + return nil, provider.NewSoftError(fmt.Errorf("failed to list tags for zone %s: %w", zoneID, err)) } tagMap := map[string]string{} for _, tag := range response.ResourceTagSet.Tags { diff --git a/provider/provider.go b/provider/provider.go index 68492183bf..6a9c591e10 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -18,6 +18,7 @@ package provider import ( "context" + "errors" "net" "strings" @@ -25,6 +26,16 @@ import ( "sigs.k8s.io/external-dns/plan" ) +// SoftError is an error, that provider will only log as error instead +// of fatal. It is meant for error propagation from providers to tell +// that this is a transient error. +var SoftError error = errors.New("soft error") + +// NewSoftError creates a SoftError from the given error +func NewSoftError(err error) error { + return errors.Join(SoftError, err) +} + // Provider defines the interface DNS providers should implement. type Provider interface { Records(ctx context.Context) ([]*endpoint.Endpoint, error)