Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ linters:
- ineffassign
- misspell
- revive
- rowserrcheck
- rowserrcheck # Checks whether Rows.Err of rows is checked successfully.
- errorlint # Checking for unchecked errors in Go code https://golangci-lint.run/usage/linters/#errcheck
- staticcheck
- unconvert
- unused
Expand Down
2 changes: 1 addition & 1 deletion internal/gen/docs/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func WriteToFile(filename string, content string) error {
file, fileErr := os.Create(filename)
if fileErr != nil {
_ = fmt.Errorf("failed to create file: %v", fileErr)
_ = fmt.Errorf("failed to create file: %w", fileErr)
}
defer file.Close()
_, writeErr := file.WriteString(content)
Expand Down
4 changes: 3 additions & 1 deletion provider/akamai/akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package akamai

import (
"context"
"errors"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -418,7 +419,8 @@ func (p AkamaiProvider) deleteRecordsets(zoneNameIDMapper provider.ZoneIDName, e
recName := strings.TrimSuffix(endpoint.DNSName, ".")
rec, err := p.client.GetRecord(zoneName, recName, endpoint.RecordType)
if err != nil {
if _, ok := err.(*dns.RecordError); !ok {
recordError := &dns.RecordError{}
if errors.As(err, &recordError) {
return fmt.Errorf("endpoint deletion. record validation failed. error: %w", err)
}
log.Infof("Endpoint deletion. Record doesn't exist. Name: %s, Type: %s", recName, endpoint.RecordType)
Expand Down
16 changes: 8 additions & 8 deletions provider/alibabacloud/alibaba_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ func NewAlibabaCloudProvider(configFile string, domainFilter endpoint.DomainFilt
if configFile != "" {
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read Alibaba Cloud config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read Alibaba Cloud config file '%s': %w", configFile, err)
}
err = yaml.Unmarshal(contents, &cfg)
if err != nil {
return nil, fmt.Errorf("failed to parse Alibaba Cloud config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to parse Alibaba Cloud config file '%s': %w", configFile, err)
}
} else {
var tmpError error
cfg, tmpError = getCloudConfigFromStsToken()
if tmpError != nil {
return nil, fmt.Errorf("failed to getCloudConfigFromStsToken: %v", tmpError)
return nil, fmt.Errorf("failed to getCloudConfigFromStsToken: %w", tmpError)
}
}

Expand All @@ -136,7 +136,7 @@ func NewAlibabaCloudProvider(configFile string, domainFilter endpoint.DomainFilt
}

if err != nil {
return nil, fmt.Errorf("failed to create Alibaba Cloud DNS client: %v", err)
return nil, fmt.Errorf("failed to create Alibaba Cloud DNS client: %w", err)
}

// Private DNS service
Expand Down Expand Up @@ -184,19 +184,19 @@ func getCloudConfigFromStsToken() (alibabaCloudConfig, error) {
roleName := ""
var err error
if roleName, err = m.RoleName(); err != nil {
return cfg, fmt.Errorf("failed to get role name from Metadata Service: %v", err)
return cfg, fmt.Errorf("failed to get role name from Metadata Service: %w", err)
}
vpcID, err := m.VpcID()
if err != nil {
return cfg, fmt.Errorf("failed to get VPC ID from Metadata Service: %v", err)
return cfg, fmt.Errorf("failed to get VPC ID from Metadata Service: %w", err)
}
regionID, err := m.Region()
if err != nil {
return cfg, fmt.Errorf("failed to get Region ID from Metadata Service: %v", err)
return cfg, fmt.Errorf("failed to get Region ID from Metadata Service: %w", err)
}
role, err := m.RamRoleToken(roleName)
if err != nil {
return cfg, fmt.Errorf("failed to get STS Token from Metadata Service: %v", err)
return cfg, fmt.Errorf("failed to get STS Token from Metadata Service: %w", err)
}
cfg.RegionID = regionID
cfg.RoleName = roleName
Expand Down
2 changes: 1 addition & 1 deletion provider/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type AzureProvider struct {
func NewAzureProvider(configFile string, domainFilter endpoint.DomainFilter, zoneNameFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, subscriptionID string, resourceGroup string, userAssignedIdentityClientID string, activeDirectoryAuthorityHost string, zonesCacheDuration time.Duration, maxRetriesCount int, dryRun bool) (*AzureProvider, error) {
cfg, err := getConfig(configFile, subscriptionID, resourceGroup, userAssignedIdentityClientID, activeDirectoryAuthorityHost)
if err != nil {
return nil, fmt.Errorf("failed to read Azure config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read Azure config file '%s': %w", configFile, err)
}

cred, clientOpts, err := getCredentials(*cfg, maxRetriesCount)
Expand Down
2 changes: 1 addition & 1 deletion provider/azure/azure_private_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type AzurePrivateDNSProvider struct {
func NewAzurePrivateDNSProvider(configFile string, domainFilter endpoint.DomainFilter, zoneNameFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, subscriptionID string, resourceGroup string, userAssignedIdentityClientID string, activeDirectoryAuthorityHost string, zonesCacheDuration time.Duration, maxRetriesCount int, dryRun bool) (*AzurePrivateDNSProvider, error) {
cfg, err := getConfig(configFile, subscriptionID, resourceGroup, userAssignedIdentityClientID, activeDirectoryAuthorityHost)
if err != nil {
return nil, fmt.Errorf("failed to read Azure config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read Azure config file '%s': %w", configFile, err)
}

cred, clientOpts, err := getCredentials(*cfg, maxRetriesCount)
Expand Down
4 changes: 2 additions & 2 deletions provider/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ type config struct {
func getConfig(configFile, subscriptionID, resourceGroup, userAssignedIdentityClientID, activeDirectoryAuthorityHost string) (*config, error) {
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read Azure config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read Azure config file '%s': %w", configFile, err)
}
cfg := &config{}
if err := json.Unmarshal(contents, &cfg); err != nil {
return nil, fmt.Errorf("failed to parse Azure config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to parse Azure config file '%s': %w", configFile, err)
}
// If a subscription ID was given, override what was present in the config file
if subscriptionID != "" {
Expand Down
2 changes: 1 addition & 1 deletion provider/azure/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func parseMaxRetries(value string, defaultValue int) (int, error) {

retries, err := strconv.Atoi(value)
if err != nil {
return 0, fmt.Errorf("invalid retry count %q: %v", value, err)
return 0, fmt.Errorf("invalid retry count %q: %w", value, err)
}

return retries, nil
Expand Down
2 changes: 1 addition & 1 deletion provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func (p *CloudFlareProvider) submitChanges(ctx context.Context, changes []*cloud
}
chs, chErr := p.listCustomHostnamesWithPagination(ctx, zoneID)
if chErr != nil {
return fmt.Errorf("could not fetch custom hostnames from zone, %v", chErr)
return fmt.Errorf("could not fetch custom hostnames from zone, %w", chErr)
}
if change.Action == cloudFlareUpdate {
if !p.submitCustomHostnameChanges(ctx, zoneID, change, chs, logFields) {
Expand Down
3 changes: 2 additions & 1 deletion provider/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/maxatome/go-testdeep/td"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/internal/testutils"
"sigs.k8s.io/external-dns/plan"
Expand Down Expand Up @@ -2100,7 +2101,7 @@ func checkFailed(name string, err error, shouldFail bool) error {
return fmt.Errorf("should fail - %q", name)
}
if !errors.Is(err, nil) && !shouldFail {
return fmt.Errorf("should not fail - %q, %v", name, err)
return fmt.Errorf("should not fail - %q, %w", name, err)
}
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion provider/google/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package google

import (
"errors"
"fmt"
"net/http"
"sort"
Expand Down Expand Up @@ -790,7 +791,8 @@ func createZone(t *testing.T, p *GoogleProvider, zone *dns.ManagedZone) {
zone.Description = "Testing zone for kubernetes.io/external-dns"

if _, err := p.managedZonesClient.Create("zalando-external-dns-test", zone).Do(); err != nil {
if err, ok := err.(*googleapi.Error); !ok || err.Code != http.StatusConflict {
var errs *googleapi.Error
if !errors.As(err, &errs) || errs.Code != http.StatusConflict {
require.NoError(t, err)
}
}
Expand Down
12 changes: 6 additions & 6 deletions provider/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ type ibmcloudChange struct {
func getConfig(configFile string) (*ibmcloudConfig, error) {
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read IBM Cloud config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read IBM Cloud config file '%s': %w", configFile, err)
}
cfg := &ibmcloudConfig{}
err = yaml.Unmarshal(contents, &cfg)
if err != nil {
return nil, fmt.Errorf("failed to read IBM Cloud config file '%s': %v", configFile, err)
return nil, fmt.Errorf("failed to read IBM Cloud config file '%s': %w", configFile, err)
}

return cfg, nil
Expand Down Expand Up @@ -241,15 +241,15 @@ func (c *ibmcloudConfig) Validate(authenticator core.Authenticator, domainFilter
Crn: core.StringPtr(c.CRN),
})
if err != nil {
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud public zones client: %v", err)
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud public zones client: %w", err)
}
if c.Endpoint != "" {
_ = service.publicZonesService.SetServiceURL(c.Endpoint)
}

zonesResp, _, err := service.publicZonesService.ListZones(&zonesv1.ListZonesOptions{})
if err != nil {
return service, isPrivate, fmt.Errorf("failed to list ibmcloud public zones: %v", err)
return service, isPrivate, fmt.Errorf("failed to list ibmcloud public zones: %w", err)
}
for _, zone := range zonesResp.Result {
log.Debugf("zoneName: %s, zoneID: %s", *zone.Name, *zone.ID)
Expand All @@ -274,7 +274,7 @@ func (c *ibmcloudConfig) Validate(authenticator core.Authenticator, domainFilter
ZoneIdentifier: core.StringPtr(zoneID),
})
if err != nil {
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud public records client: %v", err)
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud public records client: %w", err)
}
if c.Endpoint != "" {
_ = service.publicRecordsService.SetServiceURL(c.Endpoint)
Expand All @@ -286,7 +286,7 @@ func (c *ibmcloudConfig) Validate(authenticator core.Authenticator, domainFilter
Authenticator: authenticator,
})
if err != nil {
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud private records client: %v", err)
return service, isPrivate, fmt.Errorf("failed to initialize ibmcloud private records client: %w", err)
}
if c.Endpoint != "" {
_ = service.privateDNSService.SetServiceURL(c.Endpoint)
Expand Down
8 changes: 4 additions & 4 deletions provider/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (c *PDNSAPIClient) ListZones() (zones []pgo.Zone, resp *http.Response, err
return zones, resp, err
}

return zones, resp, provider.NewSoftError(fmt.Errorf("unable to list zones: %v", err))
return zones, resp, provider.NewSoftError(fmt.Errorf("unable to list zones: %w", 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,7 +190,7 @@ func (c *PDNSAPIClient) ListZone(zoneID string) (zone pgo.Zone, resp *http.Respo
return zone, resp, err
}

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

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

return resp, provider.NewSoftError(fmt.Errorf("unable to patch zone: %v", err))
return resp, provider.NewSoftError(fmt.Errorf("unable to patch zone: %w", err))
}

// PDNSProvider is an implementation of the Provider interface for PowerDNS
Expand Down Expand Up @@ -417,7 +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 {
return nil, provider.NewSoftError(fmt.Errorf("unable to fetch records: %v", err))
return nil, provider.NewSoftError(fmt.Errorf("unable to fetch records: %w", err))
}

for _, rr := range z.Rrsets {
Expand Down
3 changes: 2 additions & 1 deletion provider/pihole/clientV6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pihole
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestNewPiholeClientV6(t *testing.T) {
_, err := newPiholeClientV6(PiholeConfig{APIVersion: "6"})
if err == nil {
t.Error("Expected error from config with no server")
} else if err != ErrNoPiholeServer {
} else if !errors.Is(err, ErrNoPiholeServer) {
t.Error("Expected ErrNoPiholeServer, got", err)
}

Expand Down
3 changes: 2 additions & 1 deletion provider/pihole/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pihole
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -38,7 +39,7 @@ func TestNewPiholeClient(t *testing.T) {
_, err := newPiholeClient(PiholeConfig{})
if err == nil {
t.Error("Expected error from config with no server")
} else if err != ErrNoPiholeServer {
} else if !errors.Is(err, ErrNoPiholeServer) {
t.Error("Expected ErrNoPiholeServer, got", err)
}

Expand Down
4 changes: 2 additions & 2 deletions provider/rfc2136/rfc2136.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (r *rfc2136Provider) AddRecord(m *dns.Msg, ep *endpoint.Endpoint) error {

rr, err := dns.NewRR(newRR)
if err != nil {
return fmt.Errorf("failed to build RR: %v", err)
return fmt.Errorf("failed to build RR: %w", err)
}

m.Insert([]dns.RR{rr})
Expand All @@ -510,7 +510,7 @@ func (r *rfc2136Provider) RemoveRecord(m *dns.Msg, ep *endpoint.Endpoint) error

rr, err := dns.NewRR(newRR)
if err != nil {
return fmt.Errorf("failed to build RR: %v", err)
return fmt.Errorf("failed to build RR: %w", err)
}

m.Remove([]dns.RR{rr})
Expand Down
22 changes: 10 additions & 12 deletions provider/tencentcloud/cloudapi/tencentapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cloudapi

import (
"encoding/json"
errs "errors"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of setting an alias on std errors, wdyt of setting an alias on the specific tencentcloud errors pkg ? (like for dnspod and privatedns)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

"fmt"
"net"
"time"
Expand All @@ -43,9 +44,9 @@ func NewTencentAPIService(region string, rate int, secretId string, secretKey st
return tencentAPIService
}

////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////
// PrivateDns API
////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////

func (api *defaultTencentAPIService) CreatePrivateZoneRecord(request *privatedns.CreatePrivateZoneRecordRequest) (response *privatedns.CreatePrivateZoneRecordResponse, err error) {
apiAction := CreatePrivateZoneRecord
Expand Down Expand Up @@ -137,9 +138,9 @@ func (api *defaultTencentAPIService) DescribePrivateZoneRecordList(request *priv
return response, nil
}

////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////
// DnsPod API
////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////

func (api *defaultTencentAPIService) DescribeDomainList(request *dnspod.DescribeDomainListRequest) (response *dnspod.DescribeDomainListResponse, err error) {
apiAction := DescribeDomainList
Expand Down Expand Up @@ -231,13 +232,14 @@ func (api *defaultTencentAPIService) ModifyRecord(request *dnspod.ModifyRecordRe
return response, nil
}

////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////
// API Error Report
////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////

func dealWithError(action Action, request string, err error) bool {
log.Errorf("dealWithError %s/%s request: %s, error: %s.", action.Service, action.Name, request, err.Error())
if sdkError, ok := err.(*errors.TencentCloudSDKError); ok {
sdkError := &errors.TencentCloudSDKError{}
if errs.As(err, &sdkError) {
switch sdkError.Code {
case "RequestLimitExceeded":
return true
Expand All @@ -251,11 +253,7 @@ func dealWithError(action Action, request string, err error) bool {
return false
}

if _, ok := err.(net.Error); ok {
return true
}

return false
return errs.As(err, new(net.Error))
}

func APIErrorRecord(apiAction Action, request string, response string, err error) {
Expand Down
4 changes: 2 additions & 2 deletions provider/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewWebhookProvider(u string) (*WebhookProvider, error) {

resp, err := requestWithRetry(client, req)
if err != nil {
return nil, fmt.Errorf("failed to connect to webhook: %v", err)
return nil, fmt.Errorf("failed to connect to webhook: %w", err)
}
// read the serialized DomainFilter from the response body and set it in the webhook provider struct
defer resp.Body.Close()
Expand All @@ -134,7 +134,7 @@ func NewWebhookProvider(u string) (*WebhookProvider, error) {

df := endpoint.DomainFilter{}
if err := json.NewDecoder(resp.Body).Decode(&df); err != nil {
return nil, fmt.Errorf("failed to unmarshal response body of DomainFilter: %v", err)
return nil, fmt.Errorf("failed to unmarshal response body of DomainFilter: %w", err)
}

return &WebhookProvider{
Expand Down
Loading
Loading