Skip to content

chore(ci): update linter to v2.0.2 #5246

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
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
10 changes: 7 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ jobs:
name: Markdown, Go and OAS
runs-on: ubuntu-latest
permissions:
contents: read # to fetch code (actions/checkout)
# Required: allow read access to the content for analysis.
contents: read
# For OAS check
checks: write
# For go lang linter
pull-requests: read
steps:

- name: Check out code into the Go module directory
Expand Down Expand Up @@ -40,11 +44,11 @@ jobs:

# https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#verify
- name: Verify linter configuration and Lint go code
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
verify: true
args: --timeout=30m
version: v1.64
version: v2.0

# Run Spectral
- name: Lint OpenAPI spec
Expand Down
119 changes: 60 additions & 59 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
linters-settings:
exhaustive:
default-signifies-exhaustive: false
goimports:
local-prefixes: sigs.k8s.io/external-dns
misspell:
locale: US
revive:
ignore-generated-header: true
rules:
- name: confusing-naming
disabled: true

version: "2"
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
default: none
enable:
- dogsled
- gofmt
- goimports
- goprintffuncname
- govet
- ineffassign
- misspell
- revive
- rowserrcheck
- typecheck
- staticcheck
- unconvert
- whitespace
- revive
- unused
- gosimple
- staticcheck

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-files:
- endpoint/zz_generated.deepcopy.go
exclude-rules:
- path: _test\.go
linters:
- deadcode
- depguard
- dogsled
- gofmt
- goimports
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
- path: source/ambassador_host.go
linters: [ typecheck ]
- path: source/contour_httpproxy.go
linters: [ typecheck ]
- path: source/f5_virtualserver.go
linters: [ typecheck ]
- path: source/kong_tcpingress.go
linters: [ typecheck ]
- whitespace
settings:
exhaustive:
default-signifies-exhaustive: false
misspell:
locale: US
revive:
rules:
- name: confusing-naming
disabled: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- deadcode
- depguard
- dogsled
- goprintffuncname
- govet
- ineffassign
- misspell
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- unconvert
- unused
- varcheck
- whitespace
path: _test\.go
paths:
- endpoint/zz_generated.deepcopy.go
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- sigs.k8s.io/external-dns
exclusions:
generated: lax
paths:
- endpoint/zz_generated.deepcopy.go
- third_party$
- builtin$
- examples$
- _test\.go
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif

#? golangci-lint: Install golangci-lint tool
golangci-lint:
@command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.5
@command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.0.2

#? golangci-lint-verify: Verify golangci-lint configuration
golangci-lint-verify: golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion internal/gen/docs/flags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
flags := computeFlags()
content, err := flags.generateMarkdownTable()
if err != nil {
_ = fmt.Errorf("failed to generate markdown file '%s': %v\n", path, err.Error())
_ = fmt.Errorf("failed to generate markdown file '%s': %v", path, err.Error())
}
content = content + "\n"
_ = utils.WriteToFile(path, content)
Expand Down
7 changes: 4 additions & 3 deletions pkg/rfc2317/arpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ func CidrToInAddr(cidr string) (string, error) {
}

// Handle IPv4 Class-full and IPv6:
if total == 32 {
switch total {
case 32:
if bits%8 != 0 {
return "", fmt.Errorf("IPv4 mask must be multiple of 8 bits")
}
toTrim = (total - bits) / 8
} else if total == 128 {
case 128:
if bits%4 != 0 {
return "", fmt.Errorf("IPv6 mask must be multiple of 4 bits")
}
toTrim = (total - bits) / 4
} else {
default:
return "", fmt.Errorf("invalid address (not IPv4 or IPv6): %v", cidr)
}

Expand Down
7 changes: 4 additions & 3 deletions provider/akamai/akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,12 @@ func newAkamaiRecordset(dnsName, recordType string, ttl int, targets []string) d
// cleanTargets preps recordset rdata if necessary for EdgeDNS
func cleanTargets(rtype string, targets ...string) []string {
log.Debugf("Targets to clean: [%v]", targets)
if rtype == "CNAME" || rtype == "SRV" {
switch rtype {
case "CNAME", "SRV":
for idx, target := range targets {
targets[idx] = strings.TrimSuffix(target, ".")
}
} else if rtype == "TXT" {
case "TXT":
for idx, target := range targets {
log.Debugf("TXT data to clean: [%s]", target)
// need to embed text data in quotes. Make sure not piling on
Expand Down Expand Up @@ -359,7 +360,7 @@ func trimTxtRdata(rdata []string, rtype string) []string {
func ttlAsInt(src endpoint.TTL) int {
var temp interface{} = int64(src)
temp64 := temp.(int64)
var ttl int = edgeDNSRecordTTL
var ttl = edgeDNSRecordTTL
if temp64 > 0 && temp64 <= int64(maxInt) {
ttl = int(temp64)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/alibabacloud/alibaba_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (p *AlibabaCloudProvider) escapeTXTRecordValue(value string) string {

func (p *AlibabaCloudProvider) unescapeTXTRecordValue(value string) string {
if strings.HasPrefix(value, "heritage=") {
return fmt.Sprintf("\"%s\"", strings.Replace(value, ";", ",", -1))
return fmt.Sprintf("\"%s\"", strings.ReplaceAll(value, ";", ","))
}
return value
}
Expand Down
2 changes: 1 addition & 1 deletion provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (p *CloudFlareProvider) listDNSRecordsWithAutoPagination(ctx context.Contex
records[newDNSRecordIndex(r)] = r
}
params.ResultInfo = resultInfo.Next()
if params.ResultInfo.Done() {
if params.Done() {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion provider/gandi/gandi.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type GandiProvider struct {
func NewGandiProvider(ctx context.Context, domainFilter endpoint.DomainFilter, dryRun bool) (*GandiProvider, error) {
key, ok_key := os.LookupEnv("GANDI_KEY")
pat, ok_pat := os.LookupEnv("GANDI_PAT")
if !(ok_key || ok_pat) {
if !ok_key && !ok_pat {
return nil, errors.New("no environment variable GANDI_KEY or GANDI_PAT provided")
}
if ok_key {
Expand Down
2 changes: 1 addition & 1 deletion provider/ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (p OVHProvider) newOvhChangeUpdate(endpointsOld []*endpoint.Endpoint, endpo
toInsertTarget := []string{}

for _, target := range endpointsNew.Targets {
var toDelete int = -1
var toDelete = -1

for i, record := range oldRecords {
if target == record.Target {
Expand Down
2 changes: 1 addition & 1 deletion provider/plural/plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewPluralProvider(cluster, provider string) (*PluralProvider, error) {
endpoint := os.Getenv("PLURAL_ENDPOINT")

if token == "" {
return nil, fmt.Errorf("No plural access token provided, you must set the PLURAL_ACCESS_TOKEN env var")
return nil, fmt.Errorf("no plural access token provided, you must set the PLURAL_ACCESS_TOKEN env var")
}

config := &Config{
Expand Down
2 changes: 1 addition & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// SoftError is an error, that provider will only log as error instead
// of fatal. It is meant for error propagation from providers to tell
// that this is a transient error.
var SoftError error = errors.New("soft error")
var SoftError error = errors.New("soft error") //nolint:staticcheck

// NewSoftErrorf creates a SoftError with formats according to a format specifier and returns the string as a
func NewSoftErrorf(format string, a ...any) error {
Expand Down
9 changes: 5 additions & 4 deletions provider/tencentcloud/cloudapi/tencentapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ func (api *defaultTencentAPIService) ModifyRecord(request *dnspod.ModifyRecordRe
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 {
if sdkError.Code == "RequestLimitExceeded" {
switch sdkError.Code {
case "RequestLimitExceeded":
return true
} else if sdkError.Code == "InternalError" || sdkError.Code == "ClientError.HttpStatusCodeError" {
case "InternalError", "ClientError.HttpStatusCodeError":
return false
} else if sdkError.Code == "ClientError.NetworkError" {
case "ClientError.NetworkError":
return false
} else if sdkError.Code == "AuthFailure.UnauthorizedOperation" || sdkError.Code == "UnauthorizedOperation.CamNoAuth" {
case "AuthFailure.UnauthorizedOperation", "UnauthorizedOperation.CamNoAuth":
return false
}
return false
Expand Down
5 changes: 3 additions & 2 deletions provider/ultradns/ultradns.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ func (p *UltraDNSProvider) submitChanges(ctx context.Context, changes []*UltraDN

for zoneName, changes := range zoneChanges {
for _, change := range changes {
if change.ResourceRecordSetUltraDNS.RRType == "CNAME" {
switch change.ResourceRecordSetUltraDNS.RRType {
case "CNAME":
cnameownerName = change.ResourceRecordSetUltraDNS.OwnerName
} else if change.ResourceRecordSetUltraDNS.RRType == "TXT" {
case "TXT":
txtownerName = change.ResourceRecordSetUltraDNS.OwnerName
}

Expand Down
10 changes: 5 additions & 5 deletions source/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func legacyEndpointsFromMoleculeService(svc *v1.Service) []*endpoint.Endpoint {
return nil
}

hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
hostnameList := strings.Split(strings.ReplaceAll(hostnameAnnotation, " ", ""), ",")

for _, hostname := range hostnameList {
// Create a corresponding endpoint for each configured external entrypoint.
Expand Down Expand Up @@ -145,9 +145,9 @@ func legacyEndpointsFromDNSControllerNodePortService(svc *v1.Service, sc *servic

var hostnameList []string
if isExternal {
hostnameList = strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
hostnameList = strings.Split(strings.ReplaceAll(hostnameAnnotation, " ", ""), ",")
} else {
hostnameList = strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")
hostnameList = strings.Split(strings.ReplaceAll(internalHostnameAnnotation, " ", ""), ",")
}

for _, hostname := range hostnameList {
Expand Down Expand Up @@ -186,10 +186,10 @@ func legacyEndpointsFromDNSControllerLoadBalancerService(svc *v1.Service) []*end

var hostnameList []string
if hasExternal {
hostnameList = append(hostnameList, strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")...)
hostnameList = append(hostnameList, strings.Split(strings.ReplaceAll(hostnameAnnotation, " ", ""), ",")...)
}
if hasInternal {
hostnameList = append(hostnameList, strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")...)
hostnameList = append(hostnameList, strings.Split(strings.ReplaceAll(internalHostnameAnnotation, " ", ""), ",")...)
}

for _, hostname := range hostnameList {
Expand Down
8 changes: 4 additions & 4 deletions source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewCRDClientForAPIVersionKind(client kubernetes.Interface, kubeConfig, apiS
scheme := runtime.NewScheme()
addKnownTypes(scheme, groupVersion)

config.ContentConfig.GroupVersion = &groupVersion
config.GroupVersion = &groupVersion
config.APIPath = "/apis"
config.NegotiatedSerializer = serializer.WithoutConversionCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}

Expand Down Expand Up @@ -184,7 +184,7 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
crdEndpoints := []*endpoint.Endpoint{}
for _, ep := range dnsEndpoint.Spec.Endpoints {
if (ep.RecordType == "CNAME" || ep.RecordType == "A" || ep.RecordType == "AAAA") && len(ep.Targets) < 1 {
log.Warnf("Endpoint %s with DNSName %s has an empty list of targets", dnsEndpoint.ObjectMeta.Name, ep.DNSName)
log.Warnf("Endpoint %s with DNSName %s has an empty list of targets", dnsEndpoint.Name, ep.DNSName)
continue
}

Expand All @@ -200,7 +200,7 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
}
}
if illegalTarget {
log.Warnf("Endpoint %s with DNSName %s has an illegal target. The subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com')", dnsEndpoint.ObjectMeta.Name, ep.DNSName)
log.Warnf("Endpoint %s with DNSName %s has an illegal target. The subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com')", dnsEndpoint.Name, ep.DNSName)
continue
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error

func (cs *crdSource) setResourceLabel(crd *endpoint.DNSEndpoint, endpoints []*endpoint.Endpoint) {
for _, ep := range endpoints {
ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("crd/%s/%s", crd.ObjectMeta.Namespace, crd.ObjectMeta.Name)
ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("crd/%s/%s", crd.Namespace, crd.Name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
}

if ps.podSourceDomain != "" {
domain := pod.ObjectMeta.Name + "." + ps.podSourceDomain
domain := pod.Name + "." + ps.podSourceDomain
if len(targets) == 0 {
addToEndpointMap(endpointMap, domain, suitableType(pod.Status.PodIP), pod.Status.PodIP)
}
Expand Down
2 changes: 1 addition & 1 deletion source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ func (sc *serviceSource) extractNodePortEndpoints(svc *v1.Service, hostname stri
// take the service name from the K8s Service object
// it is safe to use since it is DNS compatible
// see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
serviceName := svc.ObjectMeta.Name
serviceName := svc.Name

// figure out the protocol
protocol := strings.ToLower(string(port.Protocol))
Expand Down
Loading
Loading