diff --git a/.golangci.yml b/.golangci.yml index fed1a177c..4be53bd71 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,7 @@ version: "2" linters: default: none enable: # golangci-lint help linters + - copyloopvar # A linter detects places where loop variables are copied. https://golangci-lint.run/usage/linters/#copyloopvar - dogsled - goprintffuncname - govet diff --git a/provider/ovh/ovh.go b/provider/ovh/ovh.go index b6c340b6e..6dd2f1ab0 100644 --- a/provider/ovh/ovh.go +++ b/provider/ovh/ovh.go @@ -223,7 +223,6 @@ func (p *OVHProvider) handleSingleZoneUpdate(ctx context.Context, zoneName strin eg, ctxErrGroup := errgroup.WithContext(ctx) for _, change := range allChanges { - change := change eg.Go(func() error { return p.change(ctxErrGroup, change) }) @@ -350,7 +349,6 @@ func (p *OVHProvider) zonesRecords(ctx context.Context) ([]string, []ovhRecord, chRecords := make(chan []ovhRecord, len(zones)) eg, ctx := errgroup.WithContext(ctx) for _, zone := range zones { - zone := zone eg.Go(func() error { return p.records(ctx, &zone, chRecords) }) } 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)) for _, id := range recordsIds { - id := id eg.Go(func() error { return p.record(ctxErrGroup, zone, id, chRecords) }) } if err := eg.Wait(); err != nil { diff --git a/source/ambassador_host_test.go b/source/ambassador_host_test.go index d6246d854..561bc1e02 100644 --- a/source/ambassador_host_test.go +++ b/source/ambassador_host_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" fakeDynamic "k8s.io/client-go/dynamic/fake" fakeKube "k8s.io/client-go/kubernetes/fake" + "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/source/annotations" ) @@ -614,7 +615,7 @@ func TestAmbassadorHostSource(t *testing.T) { expected: []*endpoint.Endpoint{}, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/connector_test.go b/source/connector_test.go index 9177d7b6b..0d6f7929c 100644 --- a/source/connector_test.go +++ b/source/connector_test.go @@ -119,7 +119,7 @@ func testConnectorSourceEndpoints(t *testing.T) { expectError: false, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/contour_httpproxy_test.go b/source/contour_httpproxy_test.go index f26afdcda..d0d42bd9d 100644 --- a/source/contour_httpproxy_test.go +++ b/source/contour_httpproxy_test.go @@ -31,6 +31,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/external-dns/endpoint" ) @@ -178,7 +179,7 @@ func TestNewContourHTTPProxySource(t *testing.T) { annotationFilter: "contour.heptio.com/ingress.class=contour", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -282,7 +283,7 @@ func testEndpointsFromHTTPProxy(t *testing.T) { expected: []*endpoint.Endpoint{}, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1034,7 +1035,7 @@ func testHTTPProxyEndpoints(t *testing.T) { ignoreHostnameAnnotation: true, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/crd_test.go b/source/crd_test.go index fb57146b8..53d8b322c 100644 --- a/source/crd_test.go +++ b/source/crd_test.go @@ -468,7 +468,7 @@ func testCRDSourceEndpoints(t *testing.T) { expectError: false, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/gateway_httproute_test.go b/source/gateway_httproute_test.go index a30bf0f3c..987bc011d 100644 --- a/source/gateway_httproute_test.go +++ b/source/gateway_httproute_test.go @@ -26,12 +26,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" 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" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" 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 { @@ -1581,7 +1582,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, } for _, tt := range tests { - tt := tt + t.Run(tt.title, func(t *testing.T) { if len(tt.logExpectations) == 0 { t.Parallel() diff --git a/source/ingress_test.go b/source/ingress_test.go index f948e6652..274837a4e 100644 --- a/source/ingress_test.go +++ b/source/ingress_test.go @@ -138,7 +138,7 @@ func TestNewIngressSource(t *testing.T) { annotationFilter: "kubernetes.io/ingress.class=nginx", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1424,7 +1424,7 @@ func testIngressEndpoints(t *testing.T) { expected: []*endpoint.Endpoint{}, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/istio_gateway_test.go b/source/istio_gateway_test.go index 43120ff3d..828353678 100644 --- a/source/istio_gateway_test.go +++ b/source/istio_gateway_test.go @@ -160,7 +160,7 @@ func TestNewIstioGatewaySource(t *testing.T) { annotationFilter: "kubernetes.io/gateway.class=nginx", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -492,7 +492,7 @@ func testEndpointsFromGatewayConfig(t *testing.T) { }, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1473,7 +1473,7 @@ func testGatewayEndpoints(t *testing.T) { expectError: true, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/istio_virtualservice_test.go b/source/istio_virtualservice_test.go index 324827814..5f18cc582 100644 --- a/source/istio_virtualservice_test.go +++ b/source/istio_virtualservice_test.go @@ -184,7 +184,7 @@ func TestNewIstioVirtualServiceSource(t *testing.T) { annotationFilter: "kubernetes.io/gateway.class=nginx", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -693,7 +693,7 @@ func testEndpointsFromVirtualServiceConfig(t *testing.T) { }, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1945,7 +1945,7 @@ func testVirtualServiceEndpoints(t *testing.T) { fqdnTemplate: "{{.Name}}.ext-dns.test.com", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/kong_tcpingress_test.go b/source/kong_tcpingress_test.go index 8f8100e3d..8325671bb 100644 --- a/source/kong_tcpingress_test.go +++ b/source/kong_tcpingress_test.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" fakeDynamic "k8s.io/client-go/dynamic/fake" fakeKube "k8s.io/client-go/kubernetes/fake" + "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.Parallel() diff --git a/source/multisource_test.go b/source/multisource_test.go index 56a3fb604..fcd9c7a40 100644 --- a/source/multisource_test.go +++ b/source/multisource_test.go @@ -73,7 +73,7 @@ func testMultiSourceEndpoints(t *testing.T) { []*endpoint.Endpoint{foo, bar}, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() diff --git a/source/node_test.go b/source/node_test.go index ddfef776e..30c4c30e1 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -22,6 +22,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" + "sigs.k8s.io/external-dns/internal/testutils" "github.com/stretchr/testify/assert" @@ -77,7 +78,7 @@ func testNodeSourceNewNodeSource(t *testing.T) { annotationFilter: "kubernetes.io/ingress.class=nginx", }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() diff --git a/source/openshift_route_test.go b/source/openshift_route_test.go index f9f7d31d7..d9b1a9b57 100644 --- a/source/openshift_route_test.go +++ b/source/openshift_route_test.go @@ -136,7 +136,7 @@ func testOcpRouteSourceNewOcpRouteSource(t *testing.T) { labelFilter: "app=web-external", }, } { - ti := ti + labelSelector, err := labels.Parse(ti.labelFilter) require.NoError(t, err) t.Run(ti.title, func(t *testing.T) { @@ -516,7 +516,7 @@ func testOcpRouteSourceEndpoints(t *testing.T) { expected: []*endpoint.Endpoint{}, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() // Create a Kubernetes testing client diff --git a/source/pod_test.go b/source/pod_test.go index 7d41a1f4d..241cd0f80 100644 --- a/source/pod_test.go +++ b/source/pod_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/external-dns/endpoint" "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.Parallel() diff --git a/source/service_test.go b/source/service_test.go index 1eaebfe56..1b6650ccb 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -145,7 +145,7 @@ func testServiceSourceNewServiceSource(t *testing.T) { serviceTypesFilter: []string{string(v1.ServiceTypeClusterIP)}, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1074,7 +1074,7 @@ func testServiceSourceEndpoints(t *testing.T) { }, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -1303,7 +1303,7 @@ func testMultipleServicesEndpoints(t *testing.T) { false, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -1611,7 +1611,7 @@ func TestClusterIpServices(t *testing.T) { expected: []*endpoint.Endpoint{}, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -2303,7 +2303,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { }}, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -3079,7 +3079,7 @@ func TestHeadlessServices(t *testing.T) { false, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -3548,7 +3548,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -3777,7 +3777,7 @@ func TestExternalServices(t *testing.T) { false, }, } { - tc := tc + t.Run(tc.title, func(t *testing.T) { t.Parallel() diff --git a/source/targetfiltersource_test.go b/source/targetfiltersource_test.go index 070d01dce..b1f6fc718 100644 --- a/source/targetfiltersource_test.go +++ b/source/targetfiltersource_test.go @@ -131,7 +131,7 @@ func TestTargetFilterSourceEndpoints(t *testing.T) { }, } for _, tt := range tests { - tt := tt + t.Run(tt.title, func(t *testing.T) { t.Parallel() diff --git a/source/traefik_proxy_test.go b/source/traefik_proxy_test.go index 4cd1cec12..60d36affa 100644 --- a/source/traefik_proxy_test.go +++ b/source/traefik_proxy_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" fakeDynamic "k8s.io/client-go/dynamic/fake" fakeKube "k8s.io/client-go/kubernetes/fake" + "sigs.k8s.io/external-dns/endpoint" ) @@ -328,7 +329,7 @@ func TestTraefikProxyIngressRouteEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -622,7 +623,7 @@ func TestTraefikProxyIngressRouteTCPEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -764,7 +765,7 @@ func TestTraefikProxyIngressRouteUDPEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1094,7 +1095,7 @@ func TestTraefikProxyOldIngressRouteEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1388,7 +1389,7 @@ func TestTraefikProxyOldIngressRouteTCPEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1530,7 +1531,7 @@ func TestTraefikProxyOldIngressRouteUDPEndpoints(t *testing.T) { expected: nil, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel() @@ -1693,7 +1694,7 @@ func TestTraefikAPIGroupDisableFlags(t *testing.T) { disableNew: true, }, } { - ti := ti + t.Run(ti.title, func(t *testing.T) { t.Parallel()