Skip to content

Commit

Permalink
Merge pull request #4166 from kubernetes-sigs/fix/softerror-should-no…
Browse files Browse the repository at this point in the history
…t-fatal

fix: provide possibility to have a soft error mode
  • Loading branch information
k8s-ci-robot authored Jan 15, 2024
2 parents 2b69c57 + b8ac272 commit 4db7b22
Show file tree
Hide file tree
Showing 3 changed files with 24 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.Fatalf("Failed to do run once: %v", err)
}
}
}
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.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 {
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.NewSoftError(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.NewSoftError(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.NewSoftError(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.NewSoftError(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.NewSoftError(fmt.Errorf("failed to list tags for zone %s: %w", zoneID, err))
}
tagMap := map[string]string{}
for _, tag := range response.ResourceTagSet.Tags {
Expand Down
11 changes: 11 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ package provider

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

"sigs.k8s.io/external-dns/endpoint"
"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)
Expand Down

0 comments on commit 4db7b22

Please sign in to comment.