Skip to content

chore(code-quality): providers linter warnings fixes #5320

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

Merged
merged 1 commit into from
Apr 26, 2025
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
34 changes: 17 additions & 17 deletions provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ const (
// We have to use pointers to bools now, as the upstream cloudflare-go library requires them
// see: https://github.com/cloudflare/cloudflare-go/pull/595

// proxyEnabled is a pointer to a bool true showing the record should be proxied through cloudflare
var proxyEnabled *bool = boolPtr(true)

// proxyDisabled is a pointer to a bool false showing the record should not be proxied through cloudflare
var proxyDisabled *bool = boolPtr(false)
var (
// proxyEnabled is a pointer to a bool true showing the record should be proxied through cloudflare
proxyEnabled *bool = boolPtr(true)
// proxyDisabled is a pointer to a bool false showing the record should not be proxied through cloudflare
proxyDisabled *bool = boolPtr(false)
)

// for faster getRecordID() lookup
type DNSRecordIndex struct {
Expand Down Expand Up @@ -279,8 +280,8 @@ func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov
if err != nil {
return nil, fmt.Errorf("failed to initialize cloudflare provider: %w", err)
}
provider := &CloudFlareProvider{
// Client: config,

return &CloudFlareProvider{
Client: zoneService{config},
domainFilter: domainFilter,
zoneIDFilter: zoneIDFilter,
Expand All @@ -289,13 +290,12 @@ func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov
DryRun: dryRun,
DNSRecordsPerPage: dnsRecordsPerPage,
RegionKey: regionKey,
}
return provider, nil
}, nil
}

// Zones returns the list of hosted zones.
func (p *CloudFlareProvider) Zones(ctx context.Context) ([]cloudflare.Zone, error) {
result := []cloudflare.Zone{}
var result []cloudflare.Zone

// if there is a zoneIDfilter configured
// && if the filter isn't just a blank string (used in tests)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (p *CloudFlareProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,
return nil, err
}

endpoints := []*endpoint.Endpoint{}
var endpoints []*endpoint.Endpoint
for _, zone := range zones {
records, err := p.listDNSRecordsWithAutoPagination(ctx, zone.ID)
if err != nil {
Expand All @@ -373,7 +373,7 @@ func (p *CloudFlareProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,

// ApplyChanges applies a given set of changes in a given zone.
func (p *CloudFlareProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
cloudflareChanges := []*cloudFlareChange{}
var cloudflareChanges []*cloudFlareChange

// if custom hostnames are enabled, deleting first allows to avoid conflicts with the new ones
if p.CustomHostnamesConfig.Enabled {
Expand Down Expand Up @@ -425,7 +425,7 @@ func (p *CloudFlareProvider) submitCustomHostnameChanges(ctx context.Context, zo
failedChange := false
// return early if disabled
if !p.CustomHostnamesConfig.Enabled {
return !failedChange
return true
}

switch change.Action {
Expand Down Expand Up @@ -730,7 +730,7 @@ func (p *CloudFlareProvider) submitChanges(ctx context.Context, changes []*cloud

// AdjustEndpoints modifies the endpoints as needed by the specific provider
func (p *CloudFlareProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
adjustedEndpoints := []*endpoint.Endpoint{}
var adjustedEndpoints []*endpoint.Endpoint
for _, e := range endpoints {
proxied := shouldBeProxied(e, p.proxiedByDefault)
if proxied {
Expand Down Expand Up @@ -969,7 +969,7 @@ func getEndpointCustomHostnames(ep *endpoint.Endpoint) []string {
}

func groupByNameAndTypeWithCustomHostnames(records DNSRecordsMap, chs CustomHostnamesMap) []*endpoint.Endpoint {
endpoints := []*endpoint.Endpoint{}
var endpoints []*endpoint.Endpoint

// group supported records by name and type
groups := map[string][]cloudflare.DNSRecord{}
Expand All @@ -994,7 +994,7 @@ func groupByNameAndTypeWithCustomHostnames(records DNSRecordsMap, chs CustomHost
customHostnames[c.CustomOriginServer] = append(customHostnames[c.CustomOriginServer], c.Hostname)
}

// create single endpoint with all the targets for each name/type
// create a single endpoint with all the targets for each name/type
for _, records := range groups {
if len(records) == 0 {
return endpoints
Expand All @@ -1016,7 +1016,7 @@ func groupByNameAndTypeWithCustomHostnames(records DNSRecordsMap, chs CustomHost
continue
}
e = e.WithProviderSpecific(source.CloudflareProxiedKey, strconv.FormatBool(proxied))
// noop (customHostnames is empty) if custom hostnames feature is not in use
// noop (customHostnames is empty) if the custom hostnames feature is not in use
if customHostnames, ok := customHostnames[records[0].Name]; ok {
sort.Strings(customHostnames)
e = e.WithProviderSpecific(source.CloudflareCustomHostnameKey, strings.Join(customHostnames, ","))
Expand Down
2 changes: 1 addition & 1 deletion provider/coredns/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type etcdClient struct {

var _ coreDNSClient = etcdClient{}

// GetService return all Service records stored in etcd stored anywhere under the given key (recursively)
// GetServices GetService return all Service records stored in etcd stored anywhere under the given key (recursively)
func (c etcdClient) GetServices(prefix string) ([]*Service, error) {
ctx, cancel := context.WithTimeout(c.ctx, etcdTimeout)
defer cancel()
Expand Down
16 changes: 8 additions & 8 deletions provider/dnsimple/dnsimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ import (
"sigs.k8s.io/external-dns/provider"
)

const dnsimpleRecordTTL = 3600 // Default TTL of 1 hour if not set (DNSimple's default)
const (
dnsimpleCreate = "CREATE"
dnsimpleDelete = "DELETE"
dnsimpleUpdate = "UPDATE"

dnsimpleRecordTTL = 3600 // Default TTL of 1 hour if not set (DNSimple's default)
)

type dnsimpleIdentityService struct {
service *dnsimple.IdentityService
Expand Down Expand Up @@ -91,12 +97,6 @@ type dnsimpleChange struct {
ResourceRecordSet dnsimple.ZoneRecord
}

const (
dnsimpleCreate = "CREATE"
dnsimpleDelete = "DELETE"
dnsimpleUpdate = "UPDATE"
)

// NewDnsimpleProvider initializes a new Dnsimple based provider
func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) {
oauthToken := os.Getenv("DNSIMPLE_OAUTH")
Expand Down Expand Up @@ -149,7 +149,7 @@ func ZonesFromZoneString(zonestring string) map[string]dnsimple.Zone {
return zones
}

// Returns a list of filtered Zones
// Zones Return a list of filtered Zones
func (p *dnsimpleProvider) Zones(ctx context.Context) (map[string]dnsimple.Zone, error) {
zones := make(map[string]dnsimple.Zone)

Expand Down
2 changes: 1 addition & 1 deletion provider/exoscale/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (ep *ExoscaleProvider) ApplyChanges(ctx context.Context, changes *plan.Chan
}

for _, epoint := range changes.UpdateOld {
// Since Exoscale "Patches", we ignore UpdateOld
// Since Exoscale "Patches", we've ignored UpdateOld
// We leave this logging here for information
log.Debugf("UPDATE-OLD (ignored) for epoint: %+v", epoint)
}
Expand Down
6 changes: 2 additions & 4 deletions provider/godaddy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ import (
"sigs.k8s.io/external-dns/pkg/apis/externaldns"
)

// DefaultTimeout api requests after 180s
const DefaultTimeout = 180 * time.Second

// Errors
var (
ErrAPIDown = errors.New("godaddy: the GoDaddy API is down")
)

// error codes
const (
ErrCodeQuotaExceeded = "QUOTA_EXCEEDED"
// DefaultTimeout api requests after 180s
DefaultTimeout = 180 * time.Second
)

// APIError error
Expand Down
4 changes: 2 additions & 2 deletions provider/godaddy/godaddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
gdCreate = 0
gdReplace = 1
gdDelete = 2

domainsURI = "/v1/domains?statuses=ACTIVE,PENDING_DNS_ACTIVE"
)

var actionNames = []string{
Expand All @@ -44,8 +46,6 @@ var actionNames = []string{
"delete",
}

const domainsURI = "/v1/domains?statuses=ACTIVE,PENDING_DNS_ACTIVE"

type gdClient interface {
Patch(string, interface{}, interface{}) error
Post(string, interface{}, interface{}) error
Expand Down
16 changes: 7 additions & 9 deletions provider/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func NewGoogleProvider(ctx context.Context, project string, domainFilter endpoin

zoneTypeFilter := provider.NewZoneTypeFilter(zoneVisibility)

provider := &GoogleProvider{
return &GoogleProvider{
project: project,
dryRun: dryRun,
batchChangeSize: batchChangeSize,
Expand All @@ -166,9 +166,7 @@ func NewGoogleProvider(ctx context.Context, project string, domainFilter endpoin
managedZonesClient: managedZonesService{dnsClient.ManagedZones},
changesClient: changesService{dnsClient.Changes},
ctx: ctx,
}

return provider, nil
}, nil
}

// Zones returns the list of hosted zones.
Expand Down Expand Up @@ -261,11 +259,11 @@ func (p *GoogleProvider) SupportedRecordType(recordType string) bool {

// newFilteredRecords returns a collection of RecordSets based on the given endpoints and domainFilter.
func (p *GoogleProvider) newFilteredRecords(endpoints []*endpoint.Endpoint) []*dns.ResourceRecordSet {
records := []*dns.ResourceRecordSet{}
var records []*dns.ResourceRecordSet

for _, endpoint := range endpoints {
if p.domainFilter.Match(endpoint.DNSName) {
records = append(records, newRecord(endpoint))
for _, ep := range endpoints {
if p.domainFilter.Match(ep.DNSName) {
records = append(records, newRecord(ep))
}
}

Expand Down Expand Up @@ -314,7 +312,7 @@ func (p *GoogleProvider) submitChange(ctx context.Context, change *dns.Change) e

// batchChange separates a zone in multiple transaction.
func batchChange(change *dns.Change, batchSize int) []*dns.Change {
changes := []*dns.Change{}
var changes []*dns.Change

if batchSize == 0 {
return append(changes, change)
Expand Down
14 changes: 7 additions & 7 deletions provider/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func NewIBMCloudProvider(configFile string, domainFilter endpoint.DomainFilter,
return nil, err
}

provider := &IBMCloudProvider{
return &IBMCloudProvider{
Client: client,
source: source,
domainFilter: domainFilter,
Expand All @@ -331,8 +331,7 @@ func NewIBMCloudProvider(configFile string, domainFilter endpoint.DomainFilter,
privateZone: isPrivate,
proxiedByDefault: proxiedByDefault,
DryRun: dryRun,
}
return provider, nil
}, nil
}

// Records gets the current records.
Expand Down Expand Up @@ -680,8 +679,8 @@ func (p *IBMCloudProvider) privateRecords(ctx context.Context) ([]*endpoint.Endp
return nil, err
}
// Filter VPC annoation for private zone active
for _, source := range sources {
vpc = checkVPCAnnotation(source)
for _, src := range sources {
vpc = checkVPCAnnotation(src)
if len(vpc) > 0 {
log.Debugf("VPC found: %s", vpc)
break
Expand Down Expand Up @@ -984,7 +983,7 @@ func checkVPCAnnotation(endpoint *endpoint.Endpoint) string {
for _, v := range endpoint.ProviderSpecific {
if v.Name == vpcFilter {
vpcCrn, err := crn.Parse(v.Value)
if vpcCrn.ResourceType != "vpc" || err != nil {
if err != nil || vpcCrn.ResourceType != "vpc" {
log.Errorf("Failed to parse vpc [%s]: %v", v.Value, err)
} else {
vpc = v.Value
Expand All @@ -1002,6 +1001,7 @@ func isNil(i interface{}) bool {
switch reflect.TypeOf(i).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(i).IsNil()
default:
return false
}
return false
}
7 changes: 3 additions & 4 deletions provider/linode/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,14 @@ func NewLinodeProvider(domainFilter endpoint.DomainFilter, dryRun bool) (*Linode
linodeClient := linodego.NewClient(oauth2Client)
linodeClient.SetUserAgent(fmt.Sprintf("%s linodego/%s", externaldns.UserAgent(), linodego.Version))

provider := &LinodeProvider{
return &LinodeProvider{
Client: &linodeClient,
domainFilter: domainFilter,
DryRun: dryRun,
}
return provider, nil
}, nil
}

// Zones returns the list of hosted zones.
// Zones return the list of hosted zones.
func (p *LinodeProvider) Zones(ctx context.Context) ([]linodego.Domain, error) {
zones, err := p.fetchZones(ctx)
if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions provider/ns1/ns1.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ func newNS1ProviderWithHTTPClient(config NS1Config, client *http.Client) (*NS1Pr

apiClient := api.NewClient(client, clientArgs...)

provider := &NS1Provider{
return &NS1Provider{
client: NS1DomainService{apiClient},
domainFilter: config.DomainFilter,
zoneIDFilter: config.ZoneIDFilter,
minTTLSeconds: config.MinTTLSeconds,
}
return provider, nil
}, nil
}

// Records returns the endpoints this provider knows about
Expand Down Expand Up @@ -257,7 +256,7 @@ func (p *NS1Provider) zonesFiltered() ([]*dns.Zone, error) {
return nil, err
}

toReturn := []*dns.Zone{}
var toReturn []*dns.Zone

for _, z := range zones {
if p.domainFilter.Match(z.Zone) && p.zoneIDFilter.Match(z.ID) {
Expand Down Expand Up @@ -292,10 +291,10 @@ func (p *NS1Provider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
func newNS1Changes(action string, endpoints []*endpoint.Endpoint) []*ns1Change {
changes := make([]*ns1Change, 0, len(endpoints))

for _, endpoint := range endpoints {
for _, ep := range endpoints {
changes = append(changes, &ns1Change{
Action: action,
Endpoint: endpoint,
Endpoint: ep,
},
)
}
Expand Down
12 changes: 6 additions & 6 deletions provider/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func mergeEndpointsMultiTargets(endpoints []*endpoint.Endpoint) []*endpoint.Endp

// Otherwise, create a new list of endpoints with the consolidated targets.
var mergedEndpoints []*endpoint.Endpoint
for _, endpoints := range endpointsByNameType {
dnsName := endpoints[0].DNSName
recordType := endpoints[0].RecordType
recordTTL := endpoints[0].RecordTTL
for _, ep := range endpointsByNameType {
dnsName := ep[0].DNSName
recordType := ep[0].RecordType
recordTTL := ep[0].RecordTTL

targets := make([]string, len(endpoints))
for i, e := range endpoints {
targets := make([]string, len(ep))
for i, e := range ep {
targets[i] = e.Targets[0]
}

Expand Down
Loading
Loading