diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7d46ad68b0..0c709a8146 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,10 +37,10 @@ jobs: go-version: stable - name: Lint Go - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: working-directory: ${{ matrix.directory }} - version: v1.64.8 # renovate: datasource=github-tags depName=golangci/golangci-lint + version: v2.0.2 # renovate: datasource=github-tags depName=golangci/golangci-lint njs-lint: name: NJS Lint diff --git a/.golangci.yml b/.golangci.yml index 707f7e6839..34c2571c1e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,64 +1,6 @@ -linters-settings: - ginkgolinter: - forbid-focus-container: true - goimports: - local-prefixes: github.com/nginx/nginx-gateway-fabric - misspell: - locale: US - revive: - ignore-generated-header: true - rules: - - name: blank-imports - - name: constant-logical-expr - - name: context-as-argument - - name: context-keys-type - - name: defer - - name: dot-imports - arguments: - - allowedPackages: - - github.com/onsi/gomega - - github.com/onsi/ginkgo/v2 - - name: duplicated-imports - - name: empty-block - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - - name: import-shadowing - - name: increment-decrement - - name: indent-error-flow - - name: package-comments - - name: range - - name: range-val-address - - name: range-val-in-closure - - name: receiver-naming - - name: redefines-builtin-id - - name: string-of-int - - name: superfluous-else - - name: time-naming - - name: unchecked-type-assertion - - name: unexported-return - - name: unnecessary-stmt - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - - name: var-naming - gocyclo: - min-complexity: 15 - govet: - enable: - - fieldalignment - lll: - line-length: 120 - dupword: - ignore: - - "test" - stylecheck: - dot-import-whitelist: - - github.com/onsi/gomega - - github.com/onsi/ginkgo/v2 +version: "2" linters: + default: none enable: - asasalint - asciicheck @@ -78,11 +20,7 @@ linters: - gocritic - gocyclo - godot - - gofmt - - gofumpt - - goimports - gosec - - gosimple - gosmopolitan - govet - ineffassign @@ -103,20 +41,98 @@ linters: - revive - spancheck - staticcheck - - stylecheck - tagalign - thelper - tparallel - - typecheck - unconvert - unparam - unused - usestdlibvars - wastedassign - whitespace - disable-all: true + settings: + dupword: + ignore: + - test + ginkgolinter: + forbid-focus-container: true + gocyclo: + min-complexity: 15 + govet: + enable: + - fieldalignment + lll: + line-length: 120 + misspell: + locale: US + revive: + rules: + - name: blank-imports + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + - name: defer + - name: dot-imports + arguments: + - allowedPackages: + - github.com/onsi/gomega + - github.com/onsi/ginkgo/v2 + - name: duplicated-imports + - name: empty-block + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: import-shadowing + - name: increment-decrement + - name: indent-error-flow + - name: package-comments + - name: range + - name: range-val-address + - name: range-val-in-closure + - name: receiver-naming + - name: redefines-builtin-id + - name: string-of-int + - name: superfluous-else + - name: time-naming + - name: unchecked-type-assertion + - name: unexported-return + - name: unnecessary-stmt + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: var-naming + staticcheck: + dot-import-whitelist: + - github.com/onsi/gomega + - github.com/onsi/ginkgo/v2 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ issues: max-issues-per-linter: 0 max-same-issues: 0 -run: - timeout: 3m +formatters: + enable: + - gofmt + - gofumpt + - goimports + settings: + goimports: + local-prefixes: + - github.com/nginx/nginx-gateway-fabric + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75b59b7a9e..63624341b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: - javascript - repo: https://github.com/golangci/golangci-lint - rev: v1.64.8 + rev: v2.0.2 hooks: - id: golangci-lint-full name: golangci-lint-root diff --git a/Makefile b/Makefile index 6cf55dcadf..1741609f75 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ GO_LINKER_FLAGS = $(GO_LINKER_FLAGS_OPTIMIZATIONS) $(GO_LINKER_FlAGS_VARS) # tools versions # renovate: datasource=github-tags depName=golangci/golangci-lint -GOLANGCI_LINT_VERSION = v1.64.8 +GOLANGCI_LINT_VERSION = v2.0.2 # renovate: datasource=docker depName=kindest/node KIND_K8S_VERSION = v1.32.3 # renovate: datasource=github-tags depName=norwoodj/helm-docs @@ -192,7 +192,7 @@ vet: ## Run go vet against code .PHONY: lint lint: ## Run golangci-lint against code - go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix + go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix .PHONY: unit-test unit-test: ## Run unit tests for the go code diff --git a/internal/mode/provisioner/deployment.go b/internal/mode/provisioner/deployment.go index 091052245e..6de1579595 100644 --- a/internal/mode/provisioner/deployment.go +++ b/internal/mode/provisioner/deployment.go @@ -19,9 +19,9 @@ func prepareDeployment(depYAML []byte, id string, gwNsName types.NamespacedName) return nil, fmt.Errorf("failed to unmarshal deployment: %w", err) } - dep.ObjectMeta.Name = id + dep.Name = id dep.Spec.Selector.MatchLabels["app"] = id - dep.Spec.Template.ObjectMeta.Labels["app"] = id + dep.Spec.Template.Labels["app"] = id finalArgs := []string{ "--gateway=" + gwNsName.String(), diff --git a/internal/mode/static/state/graph/backend_refs.go b/internal/mode/static/state/graph/backend_refs.go index 3852e900e6..76ee3ab35e 100644 --- a/internal/mode/static/state/graph/backend_refs.go +++ b/internal/mode/static/state/graph/backend_refs.go @@ -151,10 +151,10 @@ func createBackendRef( } ns := sourceNamespace - if ref.BackendRef.Namespace != nil { + if ref.Namespace != nil { ns = string(*ref.Namespace) } - svcNsName := types.NamespacedName{Name: string(ref.BackendRef.Name), Namespace: ns} + svcNsName := types.NamespacedName{Name: string(ref.Name), Namespace: ns} svcIPFamily, svcPort, err := getIPFamilyAndPortFromRef(ref.BackendRef, svcNsName, services, refPath) if err != nil { backendRef = BackendRef{ @@ -328,7 +328,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error { // capitalizing error message to match the rest of the error messages associated with a condition //nolint: stylecheck return errors.New( - "Service configured with IPv6 family but NginxProxy is configured with IPv4", + "service configured with IPv6 family but NginxProxy is configured with IPv4", ) } } @@ -337,7 +337,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error { // capitalizing error message to match the rest of the error messages associated with a condition //nolint: stylecheck return errors.New( - "Service configured with IPv4 family but NginxProxy is configured with IPv6", + "service configured with IPv4 family but NginxProxy is configured with IPv6", ) } } @@ -368,7 +368,7 @@ func validateBackendRef( ) (valid bool, cond conditions.Condition) { // Because all errors cause same condition but different reasons, we return as soon as we find an error - if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { + if ref.Group != nil && (*ref.Group != "core" && *ref.Group != "") { valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error()) } diff --git a/internal/mode/static/state/graph/backend_refs_test.go b/internal/mode/static/state/graph/backend_refs_test.go index 6b4e27f041..ba6e2a2d2d 100644 --- a/internal/mode/static/state/graph/backend_refs_test.go +++ b/internal/mode/static/state/graph/backend_refs_test.go @@ -362,7 +362,7 @@ func TestVerifyIPFamily(t *testing.T) { Valid: true, }, svcIPFamily: []v1.IPFamily{v1.IPv6Protocol}, - expErr: errors.New("Service configured with IPv6 family but NginxProxy is configured with IPv4"), + expErr: errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4"), }, { name: "Invalid - IPv6 configured for NGINX, service has only IPv4", @@ -375,7 +375,7 @@ func TestVerifyIPFamily(t *testing.T) { Valid: true, }, svcIPFamily: []v1.IPFamily{v1.IPv4Protocol}, - expErr: errors.New("Service configured with IPv4 family but NginxProxy is configured with IPv6"), + expErr: errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6"), }, { name: "Valid - When NginxProxy is nil", @@ -965,7 +965,7 @@ func TestCreateBackend(t *testing.T) { Valid: true, }, expectedCondition: helpers.GetPointer( - staticConds.NewRouteInvalidIPFamily(`Service configured with IPv4 family but NginxProxy is configured with IPv6`), + staticConds.NewRouteInvalidIPFamily(`service configured with IPv4 family but NginxProxy is configured with IPv6`), ), name: "service IPFamily doesn't match NginxProxy IPFamily", }, diff --git a/internal/mode/static/state/graph/tlsroute_test.go b/internal/mode/static/state/graph/tlsroute_test.go index 12d9beb872..ae4555ef24 100644 --- a/internal/mode/static/state/graph/tlsroute_test.go +++ b/internal/mode/static/state/graph/tlsroute_test.go @@ -482,7 +482,7 @@ func TestBuildTLSRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{staticConds.NewRouteInvalidIPFamily( - "Service configured with IPv4 family but NginxProxy is configured with IPv6", + "service configured with IPv4 family but NginxProxy is configured with IPv6", )}, Attachable: true, Valid: true, diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 24f6e4e973..845cb459fc 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -527,7 +527,7 @@ var _ = Describe("Collector", Ordered, func() { It("collects correct data for one node", func(ctx SpecContext) { k8sClientReader.ListCalls(createListCallsFunc(nodeList)) - expData.Data.ClusterNodeCount = 1 + expData.ClusterNodeCount = 1 data, err := dataCollector.Collect(ctx)