Skip to content
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

ci(linter): enable several linters #2138

Merged
merged 1 commit into from
Jun 22, 2023
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
17 changes: 13 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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
Expand All @@ -9,13 +11,20 @@ run:
linters:
fast: false
enable:
- gofmt
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved
- errcheck
- exportloopref
- gocritic
- gofumpt
- goimports
- revive
- govet
- gomodguard
- gosec
- govet
- misspell
- exportloopref
- revive
- unconvert
- unparam
- unused
- whitespace
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved
disable:
- scopelint
disable-all: false
Expand Down
8 changes: 3 additions & 5 deletions apis/v1alpha2/validation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import (
gatewayvalidationv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1/validation"
)

var (
// validateParentRefs validates ParentRefs SectionName must be set and uique
// when ParentRefs includes 2 or more references to the same parent
validateParentRefs = gatewayvalidationv1b1.ValidateParentRefs
)
// validateParentRefs validates ParentRefs SectionName must be set and uique
// when ParentRefs includes 2 or more references to the same parent
var validateParentRefs = gatewayvalidationv1b1.ValidateParentRefs

// validateBackendRefServicePort validates whether or not a port was specified
// for a backendRef which refers to a corev1.Service, asserting that the port
Expand Down
2 changes: 1 addition & 1 deletion apis/v1beta1/validation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ValidateParentRefs(parentRefs []gatewayv1b1.ParentReference, path *field.Pa
}
parentRefsSectionMap := make(map[sameKindParentRefs]sets.Set[parentQualifier])
for i, p := range parentRefs {
targetParentRefs := sameKindParentRefs{name: p.Name, namespace: *new(gatewayv1b1.Namespace), kind: *new(gatewayv1b1.Kind)}
targetParentRefs := sameKindParentRefs{name: p.Name, namespace: gatewayv1b1.Namespace(""), kind: gatewayv1b1.Kind("")}
pq := parentQualifier{}
if p.Namespace != nil {
targetParentRefs.namespace = *p.Namespace
Expand Down
2 changes: 1 addition & 1 deletion apis/v1beta1/validation/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
gatewayv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

var path = *new(field.Path)
var path = field.Path{}

func TestValidateParentRefs(t *testing.T) {
namespace := gatewayv1b1.Namespace("example-namespace")
Expand Down
7 changes: 3 additions & 4 deletions conformance/tests/gateway-modify-listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var GatewayModifyListeners = suite.ConformanceTest{
},
Manifests: []string{"tests/gateway-modify-listeners.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {

t.Run("should be able to add a listener that then becomes available for routing traffic", func(t *testing.T) {
gwNN := types.NamespacedName{Name: "gateway-add-listener", Namespace: "gateway-conformance-infra"}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand Down Expand Up @@ -93,7 +92,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "", //any reason
Reason: "", // any reason
}},
AttachedRoutes: 1,
},
Expand All @@ -106,7 +105,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "", //any reason
Reason: "", // any reason
}},
AttachedRoutes: 1,
},
Expand Down Expand Up @@ -165,7 +164,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "", //any reason
Reason: "", // any reason
}},
AttachedRoutes: 1,
},
Expand Down
1 change: 0 additions & 1 deletion conformance/tests/gateway-observed-generation-bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var GatewayObservedGenerationBump = suite.ConformanceTest{
},
Manifests: []string{"tests/gateway-observed-generation-bump.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {

gwNN := types.NamespacedName{Name: "gateway-observed-generation-bump", Namespace: "gateway-conformance-infra"}

t.Run("observedGeneration should increment", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions conformance/tests/gateway-with-attached-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var GatewayWithAttachedRoutes = suite.ConformanceTest{
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "", //any reason
Reason: "", // any reason
}},
AttachedRoutes: 1,
}}
Expand All @@ -69,7 +69,7 @@ var GatewayWithAttachedRoutes = suite.ConformanceTest{
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "", //any reason
Reason: "", // any reason
}},
AttachedRoutes: 2,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ var HTTPRouteInvalidNonExistentBackendRef = suite.ConformanceTest{
Response: http.Response{StatusCode: 500},
})
})

},
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@ var HTTPRouteInvalidBackendRefUnknownKind = suite.ConformanceTest{
Response: http.Response{StatusCode: 500},
})
})

},
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var HTTPRouteInvalidCrossNamespaceBackendRef = suite.ConformanceTest{
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

t.Run("HTTPRoute with a cross-namespace BackendRef and no ReferenceGrant has a ResolvedRefs Condition with status False and Reason RefNotPermitted", func(t *testing.T) {

resolvedRefsCond := metav1.Condition{
Type: string(v1beta1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
Expand All @@ -68,6 +67,5 @@ var HTTPRouteInvalidCrossNamespaceBackendRef = suite.ConformanceTest{
Response: http.Response{StatusCode: 500},
})
})

},
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var HTTPRoutePartiallyInvalidViaInvalidReferenceGrant = suite.ConformanceTest{
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, s.Client, s.TimeoutConfig, s.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

t.Run("HTTPRoute with BackendRef in another namespace and no ReferenceGrant covering the Service has a ResolvedRefs Condition with status False and Reason RefNotPermitted", func(t *testing.T) {

resolvedRefsCond := metav1.Condition{
Type: string(v1beta1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -80,6 +79,5 @@ var HTTPRoutePartiallyInvalidViaInvalidReferenceGrant = suite.ConformanceTest{
Namespace: "gateway-conformance-app-backend",
})
})

},
}
51 changes: 26 additions & 25 deletions conformance/tests/httproute-path-match-order.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,32 @@ var HTTPRoutePathMatchOrder = suite.ConformanceTest{
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)

testCases := []http.ExpectedResponse{{
Request: http.Request{Path: "/match/exact/one"},
Backend: "infra-backend-v3",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/exact"},
Backend: "infra-backend-v2",
Namespace: ns,
}, {
Request: http.Request{Path: "/match"},
Backend: "infra-backend-v1",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/prefix/one/any"},
Backend: "infra-backend-v2",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/prefix/any"},
Backend: "infra-backend-v1",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/any"},
Backend: "infra-backend-v3",
Namespace: ns,
},
testCases := []http.ExpectedResponse{
{
Request: http.Request{Path: "/match/exact/one"},
Backend: "infra-backend-v3",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/exact"},
Backend: "infra-backend-v2",
Namespace: ns,
}, {
Request: http.Request{Path: "/match"},
Backend: "infra-backend-v1",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/prefix/one/any"},
Backend: "infra-backend-v2",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/prefix/any"},
Backend: "infra-backend-v1",
Namespace: ns,
}, {
Request: http.Request{Path: "/match/any"},
Backend: "infra-backend-v3",
Namespace: ns,
},
}

for i := range testCases {
Expand Down
49 changes: 25 additions & 24 deletions conformance/tests/httproute-redirect-host-and-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,32 @@ var HTTPRouteRedirectHostAndStatus = suite.ConformanceTest{
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)

testCases := []http.ExpectedResponse{{
Request: http.Request{
Path: "/hostname-redirect",
UnfollowRedirect: true,
testCases := []http.ExpectedResponse{
{
Request: http.Request{
Path: "/hostname-redirect",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/host-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/host-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
},
}
for i := range testCases {
// Declare tc here to avoid loop variable
Expand Down
Loading