Skip to content

Commit

Permalink
Merge pull request #4578 from Demonware/pdns-use-soft-errors
Browse files Browse the repository at this point in the history
feat: add soft errors to pdns provider
  • Loading branch information
k8s-ci-robot authored Oct 27, 2024
2 parents aec4bf0 + ee22193 commit 7ef0e2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
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))
}

// PDNSProvider is an implementation of the Provider interface for PowerDNS
Expand Down Expand Up @@ -336,7 +334,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 @@ -419,8 +417,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 @@ -714,7 +715,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 @@ -726,7 +727,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 @@ -738,7 +739,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 @@ -902,12 +903,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 @@ -1061,6 +1064,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

0 comments on commit 7ef0e2e

Please sign in to comment.