Skip to content

chore(code-quality): added lint checks #5318

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 23, 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
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# https://golangci-lint.run/usage/configuration/
version: "2"
linters:
default: none
enable:
enable: # golangci-lint help linters
- dogsled
- goprintffuncname
- govet
Expand All @@ -13,6 +14,9 @@ linters:
- unconvert
- unused
- whitespace
- predeclared # Find code that shadows one of Go's predeclared identifiers
- sloglint # Ensure consistent code style when using log/slog
- asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name
settings:
exhaustive:
default-signifies-exhaustive: false
Expand Down
10 changes: 5 additions & 5 deletions plan/conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// ConflictResolver is used to make a decision in case of two or more different kubernetes resources
// are trying to acquire same DNS name
// are trying to acquire the same DNS name
type ConflictResolver interface {
ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint
ResolveUpdate(current *endpoint.Endpoint, candidates []*endpoint.Endpoint) *endpoint.Endpoint
Expand All @@ -38,13 +38,13 @@ type PerResource struct{}
// ResolveCreate is invoked when dns name is not owned by any resource
// ResolveCreate takes "minimal" (string comparison of Target) endpoint to acquire the DNS record
func (s PerResource) ResolveCreate(candidates []*endpoint.Endpoint) *endpoint.Endpoint {
var min *endpoint.Endpoint
var minE *endpoint.Endpoint
for _, ep := range candidates {
if min == nil || s.less(ep, min) {
min = ep
if minE == nil || s.less(ep, minE) {
minE = ep
}
}
return min
return minE
}

// ResolveUpdate is invoked when dns name is already owned by "current" endpoint
Expand Down
10 changes: 1 addition & 9 deletions provider/akamai/akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ type akamaiZone struct {
func NewAkamaiProvider(akamaiConfig AkamaiConfig, akaService AkamaiDNSService) (provider.Provider, error) {
var edgeGridConfig edgegrid.Config

/*
log.Debugf("Host: %s", akamaiConfig.ServiceConsumerDomain)
log.Debugf("ClientToken: %s", akamaiConfig.ClientToken)
log.Debugf("ClientSecret: %s", akamaiConfig.ClientSecret)
log.Debugf("AccessToken: %s", akamaiConfig.AccessToken)
log.Debugf("EdgePath: %s", akamaiConfig.EdgercPath)
log.Debugf("EdgeSection: %s", akamaiConfig.EdgercSection)
*/
// environment overrides edgerc file but config needs to be complete
if akamaiConfig.ServiceConsumerDomain == "" || akamaiConfig.ClientToken == "" || akamaiConfig.ClientSecret == "" || akamaiConfig.AccessToken == "" {
// Kubernetes config incomplete or non existent. Can't mix and match.
Expand All @@ -106,7 +98,7 @@ func NewAkamaiProvider(akamaiConfig AkamaiConfig, akaService AkamaiDNSService) (
edgeGridConfig, err = edgegrid.Init(akamaiConfig.EdgercPath, akamaiConfig.EdgercSection) // use default .edgerc location and section
if err != nil {
log.Errorf("Edgegrid Init Failed")
return &AkamaiProvider{}, err // return empty provider for backward compatibility
return &AkamaiProvider{}, err // return an empty provider for backward compatibility
}
edgeGridConfig.HeaderToSign = append(edgeGridConfig.HeaderToSign, "X-External-DNS")
} else {
Expand Down
40 changes: 16 additions & 24 deletions provider/alibabacloud/alibaba_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"github.com/aliyun/alibaba-cloud-sdk-go/services/pvtz"
"github.com/stretchr/testify/assert"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/plan"
Expand Down Expand Up @@ -223,18 +224,7 @@ func newTestAlibabaCloudProvider(private bool) *AlibabaCloudProvider {
cfg := alibabaCloudConfig{
VPCID: "vpc-xxxxxx",
}
//
//dnsClient, _ := alidns.NewClientWithAccessKey(
// cfg.RegionID,
// cfg.AccessKeyID,
// cfg.AccessKeySecret,
//)
//
//pvtzClient, _ := pvtz.NewClientWithAccessKey(
// "cn-hangzhou",
// cfg.AccessKeyID,
// cfg.AccessKeySecret,
//)

domainFilterTest := endpoint.NewDomainFilter([]string{"container-service.top.", "example.org"})

return &AlibabaCloudProvider{
Expand All @@ -256,8 +246,8 @@ func TestAlibabaCloudPrivateProvider_Records(t *testing.T) {
if len(endpoints) != 2 {
t.Errorf("Incorrect number of records: %d", len(endpoints))
}
for _, endpoint := range endpoints {
t.Logf("Endpoint for %++v", *endpoint)
for _, ep := range endpoints {
t.Logf("Endpoint for %++v", *ep)
}
}
}
Expand All @@ -271,8 +261,8 @@ func TestAlibabaCloudProvider_Records(t *testing.T) {
if len(endpoints) != 2 {
t.Errorf("Incorrect number of records: %d", len(endpoints))
}
for _, endpoint := range endpoints {
t.Logf("Endpoint for %++v", *endpoint)
for _, ep := range endpoints {
t.Logf("Endpoint for %++v", *ep)
}
}
}
Expand Down Expand Up @@ -313,16 +303,17 @@ func TestAlibabaCloudProvider_ApplyChanges(t *testing.T) {
},
}
ctx := context.Background()
p.ApplyChanges(ctx, &changes)
err := p.ApplyChanges(ctx, &changes)
assert.NoError(t, err)
endpoints, err := p.Records(ctx)
if err != nil {
t.Errorf("Failed to get records: %v", err)
} else {
if len(endpoints) != 3 {
t.Errorf("Incorrect number of records: %d", len(endpoints))
}
for _, endpoint := range endpoints {
t.Logf("Endpoint for %++v", *endpoint)
for _, ep := range endpoints {
t.Logf("Endpoint for %++v", *ep)
}
}
for _, ep := range endpoints {
Expand All @@ -343,8 +334,8 @@ func TestAlibabaCloudProvider_Records_PrivateZone(t *testing.T) {
if len(endpoints) != 2 {
t.Errorf("Incorrect number of records: %d", len(endpoints))
}
for _, endpoint := range endpoints {
t.Logf("Endpoint for %++v", *endpoint)
for _, ep := range endpoints {
t.Logf("Endpoint for %++v", *ep)
}
}
}
Expand Down Expand Up @@ -378,16 +369,17 @@ func TestAlibabaCloudProvider_ApplyChanges_PrivateZone(t *testing.T) {
},
}
ctx := context.Background()
p.ApplyChanges(ctx, &changes)
err := p.ApplyChanges(ctx, &changes)
assert.NoError(t, err)
endpoints, err := p.Records(ctx)
if err != nil {
t.Errorf("Failed to get records: %v", err)
} else {
if len(endpoints) != 2 {
t.Errorf("Incorrect number of records: %d", len(endpoints))
}
for _, endpoint := range endpoints {
t.Logf("Endpoint for %++v", *endpoint)
for _, ep := range endpoints {
t.Logf("Endpoint for %++v", *ep)
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ type profiledZone struct {
}

func (cs Route53Changes) Route53Changes() []route53types.Change {
ret := []route53types.Change{}
var ret []route53types.Change
for _, c := range cs {
ret = append(ret, c.Change)
}
Expand Down Expand Up @@ -313,7 +313,7 @@ type AWSConfig struct {

// NewAWSProvider initializes a new AWS Route53 based Provider.
func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSProvider, error) {
provider := &AWSProvider{
pr := &AWSProvider{
clients: clients,
domainFilter: awsConfig.DomainFilter,
zoneIDFilter: awsConfig.ZoneIDFilter,
Expand All @@ -331,7 +331,7 @@ func NewAWSProvider(awsConfig AWSConfig, clients map[string]Route53API) (*AWSPro
failedChangesQueue: make(map[string]Route53Changes),
}

return provider, nil
return pr, nil
}

// Zones returns the list of hosted zones.
Expand Down Expand Up @@ -561,33 +561,33 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon
}

// Identify if old and new endpoints require DELETE/CREATE instead of UPDATE.
func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, new *endpoint.Endpoint) bool {
// a change of record type
if old.RecordType != new.RecordType {
func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, newE *endpoint.Endpoint) bool {
// a change of a record type
if old.RecordType != newE.RecordType {
return true
}

// an ALIAS record change to/from an A
if old.RecordType == endpoint.RecordTypeA {
oldAlias, _ := old.GetProviderSpecificProperty(providerSpecificAlias)
newAlias, _ := new.GetProviderSpecificProperty(providerSpecificAlias)
newAlias, _ := newE.GetProviderSpecificProperty(providerSpecificAlias)
if oldAlias != newAlias {
return true
}
}

// a set identifier change
if old.SetIdentifier != new.SetIdentifier {
if old.SetIdentifier != newE.SetIdentifier {
return true
}

// a change of routing policy
// default to true for geolocation properties if any geolocation property exists in old/new but not the other
// defaults to true for geolocation properties if any geolocation property exists in old/new but not the other
for _, propType := range [7]string{providerSpecificWeight, providerSpecificRegion, providerSpecificFailover,
providerSpecificFailover, providerSpecificGeolocationContinentCode, providerSpecificGeolocationCountryCode,
providerSpecificGeolocationSubdivisionCode} {
_, oldPolicy := old.GetProviderSpecificProperty(propType)
_, newPolicy := new.GetProviderSpecificProperty(propType)
_, newPolicy := newE.GetProviderSpecificProperty(propType)
if oldPolicy != newPolicy {
return true
}
Expand All @@ -601,14 +601,14 @@ func (p *AWSProvider) createUpdateChanges(newEndpoints, oldEndpoints []*endpoint
var creates []*endpoint.Endpoint
var updates []*endpoint.Endpoint

for i, new := range newEndpoints {
old := oldEndpoints[i]
if p.requiresDeleteCreate(old, new) {
deletes = append(deletes, old)
creates = append(creates, new)
for i, newE := range newEndpoints {
oldE := oldEndpoints[i]
if p.requiresDeleteCreate(oldE, newE) {
deletes = append(deletes, oldE)
creates = append(creates, newE)
} else {
// Safe to perform an UPSERT.
updates = append(updates, new)
updates = append(updates, newE)
}
}

Expand Down Expand Up @@ -760,8 +760,8 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes Route53Changes,
func (p *AWSProvider) newChanges(action route53types.ChangeAction, endpoints []*endpoint.Endpoint) Route53Changes {
changes := make(Route53Changes, 0, len(endpoints))

for _, endpoint := range endpoints {
change := p.newChange(action, endpoint)
for _, ep := range endpoints {
change := p.newChange(action, ep)
changes = append(changes, change)
}

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 @@ -50,7 +50,7 @@ func TestGetCloudConfiguration(t *testing.T) {

func TestOverrideConfiguration(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
configFile := path.Join(path.Dir(filename), "config_test.json")
configFile := path.Join(path.Dir(filename), "fixtures/config_test.json")
cfg, err := getConfig(configFile, "subscription-override", "rg-override", "", "aad-endpoint-override")
if err != nil {
t.Errorf("got unexpected err %v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tenantId": "tenant",
"subscriptionId": "subscription",
"resourceGroup": "rg",
"aadClientId": "clientId",
"aadClientSecret": "clientSecret"
}
{
"tenantId": "tenant",
"subscriptionId": "subscription",
"resourceGroup": "rg",
"aadClientId": "clientId",
"aadClientSecret": "clientSecret"
}
10 changes: 5 additions & 5 deletions provider/exoscale/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ func (f *zoneFilter) EndpointZoneID(endpoint *endpoint.Endpoint, zones map[strin

func merge(updateOld, updateNew []*endpoint.Endpoint) []*endpoint.Endpoint {
findMatch := func(template *endpoint.Endpoint) *endpoint.Endpoint {
for _, new := range updateNew {
if template.DNSName == new.DNSName &&
template.RecordType == new.RecordType {
return new
for _, record := range updateNew {
if template.DNSName == record.DNSName &&
template.RecordType == record.RecordType {
return record
}
}
return nil
Expand All @@ -323,7 +323,7 @@ func merge(updateOld, updateNew []*endpoint.Endpoint) []*endpoint.Endpoint {
for _, old := range updateOld {
matchingNew := findMatch(old)
if matchingNew == nil {
// no match, shouldn't happen
// no match shouldn't happen
continue
}

Expand Down
23 changes: 6 additions & 17 deletions provider/godaddy/godaddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package godaddy
import (
"context"
"encoding/json"
"errors"
"fmt"
"slices"
"strings"

log "github.com/sirupsen/logrus"
Expand All @@ -46,9 +46,6 @@ var actionNames = []string{

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

// ErrRecordToMutateNotFound when ApplyChange has to update/delete and didn't found the record in the existing zone (Change with no record ID)
var ErrRecordToMutateNotFound = errors.New("record to mutate not found in current zone")

type gdClient interface {
Patch(string, interface{}, interface{}) error
Post(string, interface{}, interface{}) error
Expand Down Expand Up @@ -294,14 +291,14 @@ func (p *GDProvider) groupByNameAndType(zoneRecords []gdRecords) []*endpoint.End
recordName = strings.TrimPrefix(fmt.Sprintf("%s.%s", records[0].Name, zoneName), ".")
}

endpoint := endpoint.NewEndpointWithTTL(
ep := endpoint.NewEndpointWithTTL(
recordName,
records[0].Type,
endpoint.TTL(records[0].TTL),
targets...,
)

endpoints = append(endpoints, endpoint)
endpoints = append(endpoints, ep)
}
}

Expand Down Expand Up @@ -584,24 +581,16 @@ func countTargets(p *plan.Changes) int {
count := 0

for _, endpoints := range changes {
for _, endpoint := range endpoints {
count += len(endpoint.Targets)
for _, ep := range endpoints {
count += len(ep.Targets)
}
}

return count
}

func maxOf(vars ...int64) int64 {
max := vars[0]

for _, i := range vars {
if max < i {
max = i
}
}

return max
return slices.Max(vars)
}

func toString(obj interface{}) string {
Expand Down
Loading
Loading