Skip to content

Commit

Permalink
fix: provide possibility to have a soft error mode to only log error …
Browse files Browse the repository at this point in the history
…and not fatal

Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
  • Loading branch information
szuecs committed Jan 9, 2024
1 parent 0009a6b commit 95099b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
7 changes: 6 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -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.Fatal("Failed to do run once: %v", err)

Check failure on line 338 in controller/controller.go

View workflow job for this annotation

GitHub Actions / Build

printf: github.com/sirupsen/logrus.Fatal call has possible Printf formatting directive %v (govet)

Check failure on line 338 in controller/controller.go

View workflow job for this annotation

GitHub Actions / Build

github.com/sirupsen/logrus.Fatal call has possible Printf formatting directive %v
}
}
}
select {
Expand Down
15 changes: 7 additions & 8 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.WrapSoftError(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.WrapSoftError(fmt.Errorf("failed to list zones tags: %w", tagErr))
}

for _, zone := range zones {
Expand All @@ -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.WrapSoftError(fmt.Errorf("records retrieval failed: %w", err))
}

return p.records(ctx, zones)
Expand Down Expand Up @@ -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.WrapSoftError(fmt.Errorf("failed to list resource records sets for zone %s: %w", *z.Id, err))
}
}

Expand Down Expand Up @@ -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.WrapSoftError(fmt.Errorf("failed to list zones, not applying changes: %w", err))
}

updateChanges := p.createUpdateChanges(changes.UpdateNew, changes.UpdateOld)
Expand Down Expand Up @@ -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.WrapSoftError(fmt.Errorf("failed to submit all changes for the following zones: %v", failedZones))
}

return nil
Expand Down Expand Up @@ -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.WrapSoftError(fmt.Errorf("failed to list tags for zone %s: %w", zoneID, err))
}
tagMap := map[string]string{}
for _, tag := range response.ResourceTagSet.Tags {
Expand Down
7 changes: 7 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ package provider

import (
"context"
"errors"
"net"
"strings"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/plan"
)

var SoftError error = errors.New("soft error")

func WrapSoftError(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)
Expand Down

0 comments on commit 95099b6

Please sign in to comment.