Skip to content

Commit

Permalink
chore: golangci.yml update (#3317)
Browse files Browse the repository at this point in the history
* chore: golangci.yml updated

Signed-off-by: Mattia Lavacca <[email protected]>

* go lint

Signed-off-by: Mattia Lavacca <[email protected]>

* fixed for loops alias

aliasing in for loops no longer needed as per https://go.dev/blog/loopvar-preview

Signed-off-by: Mattia Lavacca <[email protected]>

---------

Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca authored Sep 5, 2024
1 parent ce6d2c6 commit b8dd954
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 40 deletions.
19 changes: 9 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
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

linters:
fast: false
enable:
- errcheck
- exportloopref
- copyloopvar
- gocritic
- gofumpt
- goimports
Expand All @@ -25,8 +22,6 @@ linters:
- unparam
- unused
- whitespace
disable:
- scopelint
disable-all: false
presets:
- bugs
Expand All @@ -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: []
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion apis/v1/util/validation/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion apis/v1beta1/util/validation/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions conformance/echo-basic/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/tls"
"encoding/pem"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion conformance/tests/gateway-invalid-tls-configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 0 additions & 4 deletions conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion conformance/utils/kubernetes/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
1 change: 0 additions & 1 deletion conformance/utils/suite/reports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
1 change: 0 additions & 1 deletion conformance/utils/suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion gwctl/pkg/printer/gatewayclasses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ Events: <none>
}

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)
Expand Down
6 changes: 0 additions & 6 deletions gwctl/pkg/resourcediscovery/resourcemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 0 additions & 1 deletion pkg/test/cel/grpcroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/test/cel/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b8dd954

Please sign in to comment.