diff --git a/.golangci.yml b/.golangci.yml index 8991ea2456..c1973beb5f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,10 +1,7 @@ run: timeout: 10m issues-exit-code: 1 - max-issues-per-linter: 0 - max-same-issues: 0 tests: true - skip-dirs-use-default: true modules-download-mode: readonly allow-parallel-runners: false @@ -12,7 +9,7 @@ linters: fast: false enable: - errcheck - - exportloopref + - copyloopvar - gocritic - gofumpt - goimports @@ -25,8 +22,6 @@ linters: - unparam - unused - whitespace - disable: - - scopelint disable-all: false presets: - bugs @@ -39,11 +34,13 @@ linters-settings: simplify: true goimports: local-prefixes: sigs.k8s.io/gateway-api - golint: - min-confidence: 0.9 govet: - # report about shadowed variables - check-shadowing: true + enable: + - shadow + settings: + shadow: + # Whether to be strict about shadowing; can be noisy. + strict: false misspell: locale: US ignore-words: [] @@ -58,6 +55,8 @@ linters-settings: reason: "Deprecation of package ioutil in Go 1.16." issues: + max-issues-per-linter: 0 + max-same-issues: 0 exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go diff --git a/apis/v1/util/validation/gatewayclass_test.go b/apis/v1/util/validation/gatewayclass_test.go index 7b49973bc2..d211b1fcd7 100644 --- a/apis/v1/util/validation/gatewayclass_test.go +++ b/apis/v1/util/validation/gatewayclass_test.go @@ -57,7 +57,6 @@ func TestIsControllerNameValid(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { isValid := validationtutils.IsControllerNameValid(tc.controllerName) if isValid != tc.isvalid { diff --git a/apis/v1beta1/util/validation/gatewayclass_test.go b/apis/v1beta1/util/validation/gatewayclass_test.go index 2253f702fe..175d4f9a30 100644 --- a/apis/v1beta1/util/validation/gatewayclass_test.go +++ b/apis/v1beta1/util/validation/gatewayclass_test.go @@ -57,7 +57,6 @@ func TestIsControllerNameValid(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { isValid := validationtutils.IsControllerNameValid(tc.controllerName) if isValid != tc.isvalid { diff --git a/conformance/echo-basic/grpc/grpc.go b/conformance/echo-basic/grpc/grpc.go index 25d467973b..ffb55189b9 100644 --- a/conformance/echo-basic/grpc/grpc.go +++ b/conformance/echo-basic/grpc/grpc.go @@ -20,6 +20,7 @@ import ( "context" "crypto/tls" "encoding/pem" + "errors" "fmt" "net" "os" @@ -81,9 +82,9 @@ func (s *echoServer) doEcho(methodName string, ctx context.Context, in *pb.EchoR fmt.Printf("Received over %s: %v\n", connectionType, in) mdElems, ok := metadata.FromIncomingContext(ctx) if !ok { - msg := "Failed to retrieve metadata from incoming request.\n" - fmt.Print(msg) - return nil, fmt.Errorf(msg) + msg := "failed to retrieve metadata from incoming request" + fmt.Println(msg) + return nil, errors.New(msg) } authority := "" headers := []*pb.Header{} @@ -111,15 +112,15 @@ func (s *echoServer) doEcho(methodName string, ctx context.Context, in *pb.EchoR tlsAssertions := &pb.TLSAssertions{} p, ok := peer.FromContext(ctx) if !ok { - msg := "Failed to retrieve auth info from request\n" - fmt.Print(msg) - return nil, fmt.Errorf(msg) + msg := "failed to retrieve auth info from request" + fmt.Println(msg) + return nil, errors.New(msg) } tlsInfo, ok := p.AuthInfo.(credentials.TLSInfo) if !ok { - msg := "Failed to retrieve TLS info from request\n" - fmt.Print(msg) - return nil, fmt.Errorf(msg) + msg := "failed to retrieve TLS info from request" + fmt.Println(msg) + return nil, errors.New(msg) } switch tlsInfo.State.Version { case tls.VersionTLS13: diff --git a/conformance/tests/gateway-invalid-tls-configuration.go b/conformance/tests/gateway-invalid-tls-configuration.go index c48fe03d86..20b4c12bb8 100644 --- a/conformance/tests/gateway-invalid-tls-configuration.go +++ b/conformance/tests/gateway-invalid-tls-configuration.go @@ -77,7 +77,6 @@ var GatewayInvalidTLSConfiguration = suite.ConformanceTest{ } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, tc.gatewayNamespacedName, listeners) diff --git a/conformance/utils/kubernetes/apply.go b/conformance/utils/kubernetes/apply.go index 7346a4b108..983e0715e1 100644 --- a/conformance/utils/kubernetes/apply.go +++ b/conformance/utils/kubernetes/apply.go @@ -216,8 +216,6 @@ func (a Applier) prepareResources(t *testing.T, decoder *yaml.YAMLOrJSONDecoder) func (a Applier) MustApplyObjectsWithCleanup(t *testing.T, c client.Client, timeoutConfig config.TimeoutConfig, resources []client.Object, cleanup bool) { for _, resource := range resources { - resource := resource - ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.CreateTimeout) defer cancel() diff --git a/conformance/utils/kubernetes/helpers.go b/conformance/utils/kubernetes/helpers.go index 02ee9ed404..9134a2c441 100644 --- a/conformance/utils/kubernetes/helpers.go +++ b/conformance/utils/kubernetes/helpers.go @@ -206,8 +206,6 @@ func NamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig config.T tlog.Errorf(t, "Error listing Gateways: %v", err) } for _, gw := range gwList.Items { - gw := gw - if val, ok := gw.Annotations[GatewayExcludedFromReadinessChecks]; ok && val == "true" { tlog.Logf(t, "Gateway %s is skipped for setup and wont be tested", client.ObjectKeyFromObject(&gw)) continue @@ -237,7 +235,6 @@ func NamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig config.T tlog.Errorf(t, "Error listing Pods: %v", err) } for _, pod := range podList.Items { - pod := pod if !findPodConditionInList(t, pod.Status.Conditions, "Ready", "True") && pod.Status.Phase != v1.PodSucceeded && pod.DeletionTimestamp == nil { @@ -309,7 +306,6 @@ func MeshNamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig conf tlog.Errorf(t, "Error listing Pods: %v", err) } for _, pod := range podList.Items { - pod := pod if !findPodConditionInList(t, pod.Status.Conditions, "Ready", "True") && pod.Status.Phase != v1.PodSucceeded && pod.DeletionTimestamp == nil { diff --git a/conformance/utils/kubernetes/helpers_test.go b/conformance/utils/kubernetes/helpers_test.go index 7b828b600e..9c2ed0eb6d 100644 --- a/conformance/utils/kubernetes/helpers_test.go +++ b/conformance/utils/kubernetes/helpers_test.go @@ -313,7 +313,6 @@ func Test_listenersMatch(t *testing.T) { } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { assert.Equal(t, test.want, listenersMatch(t, test.expected, test.actual)) }) diff --git a/conformance/utils/suite/reports_test.go b/conformance/utils/suite/reports_test.go index d01503f314..27371a7c5e 100644 --- a/conformance/utils/suite/reports_test.go +++ b/conformance/utils/suite/reports_test.go @@ -114,7 +114,6 @@ func TestBuildSummary(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tc := tc summary := buildSummary(tc.report) require.Equal(t, tc.expectedSummary, summary) }) diff --git a/conformance/utils/suite/suite_test.go b/conformance/utils/suite/suite_test.go index 47d00a0b42..58be60bec0 100644 --- a/conformance/utils/suite/suite_test.go +++ b/conformance/utils/suite/suite_test.go @@ -168,7 +168,6 @@ func TestGetAPIVersionAndChannel(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { version, channel, err := getAPIVersionAndChannel(tc.crds) assert.Equal(t, tc.expectedVersion, version) diff --git a/gwctl/pkg/printer/gatewayclasses_test.go b/gwctl/pkg/printer/gatewayclasses_test.go index 0a76050422..56058a76d8 100644 --- a/gwctl/pkg/printer/gatewayclasses_test.go +++ b/gwctl/pkg/printer/gatewayclasses_test.go @@ -316,7 +316,6 @@ Events: } for _, tc := range testcases { - tc := tc t.Run(tc.name, func(t *testing.T) { k8sClients := common.MustClientsForTest(t, tc.objects...) policyManager := utils.MustPolicyManagerForTest(t, k8sClients) diff --git a/gwctl/pkg/resourcediscovery/resourcemodel.go b/gwctl/pkg/resourcediscovery/resourcemodel.go index 831d75bcb8..e06ffb0025 100644 --- a/gwctl/pkg/resourcediscovery/resourcemodel.go +++ b/gwctl/pkg/resourcediscovery/resourcemodel.go @@ -55,7 +55,6 @@ func (rm *ResourceModel) addGatewayClasses(gatewayClasses ...gatewayv1.GatewayCl rm.GatewayClasses = make(map[gatewayClassID]*GatewayClassNode) } for _, gatewayClass := range gatewayClasses { - gatewayClass := gatewayClass gatewayClassNode := NewGatewayClassNode(&gatewayClass) if _, ok := rm.GatewayClasses[gatewayClassNode.ID()]; !ok { rm.GatewayClasses[gatewayClassNode.ID()] = gatewayClassNode @@ -82,7 +81,6 @@ func (rm *ResourceModel) addGateways(gateways ...gatewayv1.Gateway) { rm.Gateways = make(map[gatewayID]*GatewayNode) } for _, gateway := range gateways { - gateway := gateway gatewayNode := NewGatewayNode(&gateway) if _, ok := rm.Gateways[gatewayNode.ID()]; !ok { rm.Gateways[gatewayNode.ID()] = gatewayNode @@ -96,7 +94,6 @@ func (rm *ResourceModel) addHTTPRoutes(httpRoutes ...gatewayv1.HTTPRoute) { rm.HTTPRoutes = make(map[httpRouteID]*HTTPRouteNode) } for _, httpRoute := range httpRoutes { - httpRoute := httpRoute httpRouteNode := NewHTTPRouteNode(&httpRoute) if _, ok := rm.HTTPRoutes[httpRouteNode.ID()]; !ok { rm.HTTPRoutes[httpRouteNode.ID()] = httpRouteNode @@ -110,7 +107,6 @@ func (rm *ResourceModel) addBackends(backends ...unstructured.Unstructured) { rm.Backends = make(map[backendID]*BackendNode) } for _, backend := range backends { - backend := backend backendNode := NewBackendNode(&backend) if _, ok := rm.Backends[backendNode.ID()]; !ok { rm.Backends[backendNode.ID()] = backendNode @@ -124,7 +120,6 @@ func (rm *ResourceModel) addReferenceGrants(referenceGrants ...gatewayv1beta1.Re rm.ReferenceGrants = make(map[referenceGrantID]*ReferenceGrantNode) } for _, referenceGrant := range referenceGrants { - referenceGrant := referenceGrant referenceGrantNode := NewReferenceGrantNode(&referenceGrant) if _, ok := rm.ReferenceGrants[referenceGrantNode.ID()]; !ok { rm.ReferenceGrants[referenceGrantNode.ID()] = referenceGrantNode @@ -140,7 +135,6 @@ func (rm *ResourceModel) addPolicyIfTargetExists(policies ...policymanager.Polic rm.Policies = make(map[policyID]*PolicyNode) } for _, policy := range policies { - policy := policy policyNode := NewPolicyNode(&policy) switch { diff --git a/hack/verify-golint.sh b/hack/verify-golint.sh index 8fab429269..584bfe9b16 100755 --- a/hack/verify-golint.sh +++ b/hack/verify-golint.sh @@ -18,7 +18,7 @@ set -o errexit set -o nounset set -o pipefail -readonly VERSION="v1.57.2" +readonly VERSION="v1.60.3" readonly KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. cd "${KUBE_ROOT}" diff --git a/pkg/test/cel/grpcroute_test.go b/pkg/test/cel/grpcroute_test.go index 4c76e9fa12..4dae7f4b1c 100644 --- a/pkg/test/cel/grpcroute_test.go +++ b/pkg/test/cel/grpcroute_test.go @@ -389,7 +389,6 @@ func TestGRPCMethodMatch(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { route := gatewayv1.GRPCRoute{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/test/cel/httproute_test.go b/pkg/test/cel/httproute_test.go index a20a70cf27..cb837f8d21 100644 --- a/pkg/test/cel/httproute_test.go +++ b/pkg/test/cel/httproute_test.go @@ -150,6 +150,7 @@ func TestHTTPPathMatch(t *testing.T) { func TestBackendObjectReference(t *testing.T) { portPtr := func(n int) *gatewayv1.PortNumber { + //nolint:gosec p := gatewayv1.PortNumber(n) return &p }