chore(codebase): enable copyloopvar

This commit is contained in:
ivan katliarchuk 2025-05-20 09:26:24 +01:00
parent 718ee660ff
commit 11fd3a87aa
No known key found for this signature in database
GPG Key ID: 90C9B4748A999097
18 changed files with 48 additions and 43 deletions

View File

@ -3,6 +3,7 @@ version: "2"
linters: linters:
default: none default: none
enable: # golangci-lint help linters enable: # golangci-lint help linters
- copyloopvar # A linter detects places where loop variables are copied. https://golangci-lint.run/usage/linters/#copyloopvar
- dogsled - dogsled
- goprintffuncname - goprintffuncname
- govet - govet

View File

@ -223,7 +223,6 @@ func (p *OVHProvider) handleSingleZoneUpdate(ctx context.Context, zoneName strin
eg, ctxErrGroup := errgroup.WithContext(ctx) eg, ctxErrGroup := errgroup.WithContext(ctx)
for _, change := range allChanges { for _, change := range allChanges {
change := change
eg.Go(func() error { eg.Go(func() error {
return p.change(ctxErrGroup, change) return p.change(ctxErrGroup, change)
}) })
@ -350,7 +349,6 @@ func (p *OVHProvider) zonesRecords(ctx context.Context) ([]string, []ovhRecord,
chRecords := make(chan []ovhRecord, len(zones)) chRecords := make(chan []ovhRecord, len(zones))
eg, ctx := errgroup.WithContext(ctx) eg, ctx := errgroup.WithContext(ctx)
for _, zone := range zones { for _, zone := range zones {
zone := zone
eg.Go(func() error { return p.records(ctx, &zone, chRecords) }) eg.Go(func() error { return p.records(ctx, &zone, chRecords) })
} }
if err := eg.Wait(); err != nil { if err := eg.Wait(); err != nil {
@ -430,7 +428,6 @@ func (p *OVHProvider) records(ctx context.Context, zone *string, records chan<-
} }
chRecords := make(chan ovhRecord, len(recordsIds)) chRecords := make(chan ovhRecord, len(recordsIds))
for _, id := range recordsIds { for _, id := range recordsIds {
id := id
eg.Go(func() error { return p.record(ctxErrGroup, zone, id, chRecords) }) eg.Go(func() error { return p.record(ctxErrGroup, zone, id, chRecords) })
} }
if err := eg.Wait(); err != nil { if err := eg.Wait(); err != nil {

View File

@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
fakeDynamic "k8s.io/client-go/dynamic/fake" fakeDynamic "k8s.io/client-go/dynamic/fake"
fakeKube "k8s.io/client-go/kubernetes/fake" fakeKube "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/source/annotations" "sigs.k8s.io/external-dns/source/annotations"
) )
@ -614,7 +615,7 @@ func TestAmbassadorHostSource(t *testing.T) {
expected: []*endpoint.Endpoint{}, expected: []*endpoint.Endpoint{},
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -119,7 +119,7 @@ func testConnectorSourceEndpoints(t *testing.T) {
expectError: false, expectError: false,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/endpoint"
) )
@ -178,7 +179,7 @@ func TestNewContourHTTPProxySource(t *testing.T) {
annotationFilter: "contour.heptio.com/ingress.class=contour", annotationFilter: "contour.heptio.com/ingress.class=contour",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -282,7 +283,7 @@ func testEndpointsFromHTTPProxy(t *testing.T) {
expected: []*endpoint.Endpoint{}, expected: []*endpoint.Endpoint{},
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1034,7 +1035,7 @@ func testHTTPProxyEndpoints(t *testing.T) {
ignoreHostnameAnnotation: true, ignoreHostnameAnnotation: true,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -468,7 +468,7 @@ func testCRDSourceEndpoints(t *testing.T) {
expectError: false, expectError: false,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -26,12 +26,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
kubefake "k8s.io/client-go/kubernetes/fake" kubefake "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/internal/testutils"
"sigs.k8s.io/external-dns/source/annotations"
v1 "sigs.k8s.io/gateway-api/apis/v1" v1 "sigs.k8s.io/gateway-api/apis/v1"
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake" gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/internal/testutils"
"sigs.k8s.io/external-dns/source/annotations"
) )
func mustGetLabelSelector(s string) labels.Selector { func mustGetLabelSelector(s string) labels.Selector {
@ -1581,7 +1582,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.title, func(t *testing.T) { t.Run(tt.title, func(t *testing.T) {
if len(tt.logExpectations) == 0 { if len(tt.logExpectations) == 0 {
t.Parallel() t.Parallel()

View File

@ -138,7 +138,7 @@ func TestNewIngressSource(t *testing.T) {
annotationFilter: "kubernetes.io/ingress.class=nginx", annotationFilter: "kubernetes.io/ingress.class=nginx",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1424,7 +1424,7 @@ func testIngressEndpoints(t *testing.T) {
expected: []*endpoint.Endpoint{}, expected: []*endpoint.Endpoint{},
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -160,7 +160,7 @@ func TestNewIstioGatewaySource(t *testing.T) {
annotationFilter: "kubernetes.io/gateway.class=nginx", annotationFilter: "kubernetes.io/gateway.class=nginx",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -492,7 +492,7 @@ func testEndpointsFromGatewayConfig(t *testing.T) {
}, },
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1473,7 +1473,7 @@ func testGatewayEndpoints(t *testing.T) {
expectError: true, expectError: true,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -184,7 +184,7 @@ func TestNewIstioVirtualServiceSource(t *testing.T) {
annotationFilter: "kubernetes.io/gateway.class=nginx", annotationFilter: "kubernetes.io/gateway.class=nginx",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -693,7 +693,7 @@ func testEndpointsFromVirtualServiceConfig(t *testing.T) {
}, },
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1945,7 +1945,7 @@ func testVirtualServiceEndpoints(t *testing.T) {
fqdnTemplate: "{{.Name}}.ext-dns.test.com", fqdnTemplate: "{{.Name}}.ext-dns.test.com",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
fakeDynamic "k8s.io/client-go/dynamic/fake" fakeDynamic "k8s.io/client-go/dynamic/fake"
fakeKube "k8s.io/client-go/kubernetes/fake" fakeKube "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/endpoint"
) )
@ -342,7 +343,7 @@ func TestKongTCPIngressEndpoints(t *testing.T) {
}, },
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -73,7 +73,7 @@ func testMultiSourceEndpoints(t *testing.T) {
[]*endpoint.Endpoint{foo, bar}, []*endpoint.Endpoint{foo, bar},
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -22,6 +22,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test" "github.com/sirupsen/logrus/hooks/test"
"sigs.k8s.io/external-dns/internal/testutils" "sigs.k8s.io/external-dns/internal/testutils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -77,7 +78,7 @@ func testNodeSourceNewNodeSource(t *testing.T) {
annotationFilter: "kubernetes.io/ingress.class=nginx", annotationFilter: "kubernetes.io/ingress.class=nginx",
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -136,7 +136,7 @@ func testOcpRouteSourceNewOcpRouteSource(t *testing.T) {
labelFilter: "app=web-external", labelFilter: "app=web-external",
}, },
} { } {
ti := ti
labelSelector, err := labels.Parse(ti.labelFilter) labelSelector, err := labels.Parse(ti.labelFilter)
require.NoError(t, err) require.NoError(t, err)
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
@ -516,7 +516,7 @@ func testOcpRouteSourceEndpoints(t *testing.T) {
expected: []*endpoint.Endpoint{}, expected: []*endpoint.Endpoint{},
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
// Create a Kubernetes testing client // Create a Kubernetes testing client

View File

@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/endpoint"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
@ -599,7 +600,7 @@ func TestPodSource(t *testing.T) {
}, },
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -145,7 +145,7 @@ func testServiceSourceNewServiceSource(t *testing.T) {
serviceTypesFilter: []string{string(v1.ServiceTypeClusterIP)}, serviceTypesFilter: []string{string(v1.ServiceTypeClusterIP)},
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1074,7 +1074,7 @@ func testServiceSourceEndpoints(t *testing.T) {
}, },
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1303,7 +1303,7 @@ func testMultipleServicesEndpoints(t *testing.T) {
false, false,
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1611,7 +1611,7 @@ func TestClusterIpServices(t *testing.T) {
expected: []*endpoint.Endpoint{}, expected: []*endpoint.Endpoint{},
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -2303,7 +2303,7 @@ func TestServiceSourceNodePortServices(t *testing.T) {
}}, }},
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -3079,7 +3079,7 @@ func TestHeadlessServices(t *testing.T) {
false, false,
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -3548,7 +3548,7 @@ func TestHeadlessServicesHostIP(t *testing.T) {
false, false,
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -3777,7 +3777,7 @@ func TestExternalServices(t *testing.T) {
false, false,
}, },
} { } {
tc := tc
t.Run(tc.title, func(t *testing.T) { t.Run(tc.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -131,7 +131,7 @@ func TestTargetFilterSourceEndpoints(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.title, func(t *testing.T) { t.Run(tt.title, func(t *testing.T) {
t.Parallel() t.Parallel()

View File

@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
fakeDynamic "k8s.io/client-go/dynamic/fake" fakeDynamic "k8s.io/client-go/dynamic/fake"
fakeKube "k8s.io/client-go/kubernetes/fake" fakeKube "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/endpoint"
) )
@ -328,7 +329,7 @@ func TestTraefikProxyIngressRouteEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -622,7 +623,7 @@ func TestTraefikProxyIngressRouteTCPEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -764,7 +765,7 @@ func TestTraefikProxyIngressRouteUDPEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1094,7 +1095,7 @@ func TestTraefikProxyOldIngressRouteEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1388,7 +1389,7 @@ func TestTraefikProxyOldIngressRouteTCPEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1530,7 +1531,7 @@ func TestTraefikProxyOldIngressRouteUDPEndpoints(t *testing.T) {
expected: nil, expected: nil,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -1693,7 +1694,7 @@ func TestTraefikAPIGroupDisableFlags(t *testing.T) {
disableNew: true, disableNew: true,
}, },
} { } {
ti := ti
t.Run(ti.title, func(t *testing.T) { t.Run(ti.title, func(t *testing.T) {
t.Parallel() t.Parallel()