mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-05 17:16:59 +02:00
fix: provide possibility to have a soft error mode to only log error and not fatal
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
This commit is contained in:
parent
0009a6b67b
commit
1ee6c0a77d
@ -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 {
|
||||
|
@ -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.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 {
|
||||
@ -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)
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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 {
|
||||
|
@ -18,6 +18,7 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
@ -25,6 +26,12 @@ import (
|
||||
"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)
|
||||
|
Loading…
Reference in New Issue
Block a user