Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add soft errors to pdns provider #4578

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions provider/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"math"
"net"
"net/http"
Expand Down Expand Up @@ -156,8 +157,7 @@ func (c *PDNSAPIClient) ListZones() (zones []pgo.Zone, resp *http.Response, err
return zones, resp, err
}

log.Errorf("Unable to fetch zones. %v", err)
return zones, resp, err
return zones, resp, provider.NewSoftError(fmt.Errorf("unable to list zones: %v", err))
}

// PartitionZones : Method returns a slice of zones that adhere to the domain filter and a slice of ones that does not adhere to the filter
Expand Down Expand Up @@ -190,8 +190,7 @@ func (c *PDNSAPIClient) ListZone(zoneID string) (zone pgo.Zone, resp *http.Respo
return zone, resp, err
}

log.Errorf("Unable to list zone. %v", err)
return zone, resp, err
return zone, resp, provider.NewSoftError(fmt.Errorf("unable to list zone: %v", err))
}

// PatchZone : Method used to update the contents of a particular zone from PowerDNS
Expand All @@ -208,8 +207,7 @@ func (c *PDNSAPIClient) PatchZone(zoneID string, zoneStruct pgo.Zone) (resp *htt
return resp, err
}

log.Errorf("Unable to patch zone. %v", err)
return resp, err
return resp, provider.NewSoftError(fmt.Errorf("unable to patch zone: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it fails when trying to update record, after multiple retries, I think this one should be a regular error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a soft error. In a lot of cases, failing to update a record is due to user error. If the error is logged, then a user can "fix" the record definition and it can be applied on another run. Returning a regular error here bubbles up to a fatal error in the controller. Since the error is often recoverable, I think a soft error makes more sense. The AWS provider also returns a soft error when it cannot apply some changes.

}

// PDNSProvider is an implementation of the Provider interface for PowerDNS
Expand Down Expand Up @@ -335,7 +333,7 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
// DELETEs explicitly forbid a TTL, therefore only PATCHes need the TTL
if changetype == PdnsReplace {
if int64(ep.RecordTTL) > int64(math.MaxInt32) {
return nil, errors.New("value of record TTL overflows, limited to int32")
return nil, provider.NewSoftError(fmt.Errorf("value of record TTL overflows, limited to int32"))
}
if ep.RecordTTL == 0 {
// No TTL was specified for the record, we use the default
Expand Down Expand Up @@ -418,8 +416,7 @@ func (p *PDNSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpo
for _, zone := range filteredZones {
z, _, err := p.client.ListZone(zone.Id)
if err != nil {
log.Warnf("Unable to fetch Records")
return nil, err
return nil, provider.NewSoftError(fmt.Errorf("unable to fetch records: %v", err))
}

for _, rr := range z.Rrsets {
Expand Down
12 changes: 8 additions & 4 deletions provider/pdns/pdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package pdns

import (
"context"
"errors"
"fmt"
"net/http"
"regexp"
"strings"
Expand All @@ -29,6 +29,7 @@ import (
"github.com/stretchr/testify/suite"

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

// FIXME: What do we do about labels?
Expand Down Expand Up @@ -691,7 +692,7 @@ type PDNSAPIClientStubPatchZoneFailure struct {

// Just overwrite the PatchZone method to introduce a failure
func (c *PDNSAPIClientStubPatchZoneFailure) PatchZone(zoneID string, zoneStruct pgo.Zone) (*http.Response, error) {
return nil, errors.New("Generic PDNS Error")
return nil, provider.NewSoftError(fmt.Errorf("Generic PDNS Error"))
}

/******************************************************************************/
Expand All @@ -703,7 +704,7 @@ type PDNSAPIClientStubListZoneFailure struct {

// Just overwrite the ListZone method to introduce a failure
func (c *PDNSAPIClientStubListZoneFailure) ListZone(zoneID string) (pgo.Zone, *http.Response, error) {
return pgo.Zone{}, nil, errors.New("Generic PDNS Error")
return pgo.Zone{}, nil, provider.NewSoftError(fmt.Errorf("Generic PDNS Error"))
}

/******************************************************************************/
Expand All @@ -715,7 +716,7 @@ type PDNSAPIClientStubListZonesFailure struct {

// Just overwrite the ListZones method to introduce a failure
func (c *PDNSAPIClientStubListZonesFailure) ListZones() ([]pgo.Zone, *http.Response, error) {
return []pgo.Zone{}, nil, errors.New("Generic PDNS Error")
return []pgo.Zone{}, nil, provider.NewSoftError(fmt.Errorf("Generic PDNS Error"))
}

/******************************************************************************/
Expand Down Expand Up @@ -879,12 +880,14 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSRecords() {
}
_, err = p.Records(ctx)
assert.NotNil(suite.T(), err)
assert.ErrorIs(suite.T(), err, provider.SoftError)

p = &PDNSProvider{
client: &PDNSAPIClientStubListZonesFailure{},
}
_, err = p.Records(ctx)
assert.NotNil(suite.T(), err)
assert.ErrorIs(suite.T(), err, provider.SoftError)
}

func (suite *NewPDNSProviderTestSuite) TestPDNSConvertEndpointsToZones() {
Expand Down Expand Up @@ -1024,6 +1027,7 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSmutateRecords() {
// Check inserting endpoints from a single zone
err = p.mutateRecords(endpointsSimpleRecord, pdnsChangeType("REPLACE"))
assert.NotNil(suite.T(), err)
assert.ErrorIs(suite.T(), err, provider.SoftError)
}

func (suite *NewPDNSProviderTestSuite) TestPDNSClientPartitionZones() {
Expand Down
Loading