From 596fdaae197b9b70ee2668f746a59f87cee89304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Mon, 14 Jul 2025 16:11:03 +0200 Subject: [PATCH 1/4] golangci-lint: Bumping to a version compatible with go 1.24 Golangci-lint v1.64 is the first one to support go 1.24, which is the version of go we're now getting in the CI jobs. --- hack/tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/tools/Makefile b/hack/tools/Makefile index 60f45a9955..3f2771daae 100644 --- a/hack/tools/Makefile +++ b/hack/tools/Makefile @@ -15,7 +15,7 @@ ROOT_DIR_RELATIVE := ../.. include $(ROOT_DIR_RELATIVE)/common.mk -GOLANGCI_LINT_VERSION := v1.54.2 +GOLANGCI_LINT_VERSION := v1.64.8 UNAME := $(shell uname -s) From 6f4f7be764b1dc66660ddb469e8507e0aff721e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Mon, 14 Jul 2025 16:32:12 +0200 Subject: [PATCH 2/4] golangci-lint: replace exportloopref linter with copyloopvar We were getting an error: WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar. ERRO [linters_context] exportloopref: This linter is fully inactivated: it will not produce any reports. --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index dd62b87cb9..d50789ce2d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,13 +5,13 @@ linters: - asciicheck - bidichk - bodyclose + - copyloopvar - cyclop # - depguard - dogsled - dupword - durationcheck - errcheck - - exportloopref - forbidigo - gci - goconst From 4201766c60965a13aaab09649517417de5b2d576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Mon, 14 Jul 2025 16:33:10 +0200 Subject: [PATCH 3/4] golangci-lint: Fix deprecation warnings There were a couple of deprecation warnings after bumping golangci-lint version: WARN [linters_context] copyloopvar: this linter is disabled because the Go version (1.20) of your project is lower than Go 1.22 WARN [config_reader] The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`. WARN [config_reader] The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`. WARN [config_reader] The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`. WARN [config_reader] The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`. --- .golangci.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d50789ce2d..98a30c5100 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,8 @@ linters: - asciicheck - bidichk - bodyclose - - copyloopvar + # Commented out as this linter doesn't work against go 1.20 projects + # - copyloopvar - cyclop # - depguard - dogsled @@ -56,7 +57,10 @@ linters-settings: # TODO(sbuerin) fix remaining findings and set to 20 afterwards max-complexity: 30 gci: - local-prefixes: sigs.k8s.io/cluster-api-provider-openstack + sections: + - standard + - default + - prefix(sigs.k8s.io/cluster-api-provider-openstack) gocritic: enabled-tags: - diagnostic @@ -129,10 +133,6 @@ linters-settings: nolintlint: # https://github.com/golangci/golangci-lint/issues/3228 allow-unused: true - staticcheck: - go: "1.20" - stylecheck: - go: "1.20" nestif: # minimal complexity of if statements to report, 5 by default # TODO(sbuerin) fix remaining findings and set to 5 after: @@ -171,12 +171,13 @@ issues: - stylecheck text: "ST1003: should not use underscores in Go names;" path: .*(api|types)\/.*\/.*conversion.*\.go$ + exclude-files: + - "zz_generated.*\\.go$" run: timeout: 10m build-tags: - e2e + go: "1.20" - skip-files: - - "zz_generated.*\\.go$" allow-parallel-runners: true From 5541d6e31cf155263a61fdbf525076ef6ceec32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Mon, 14 Jul 2025 17:27:19 +0200 Subject: [PATCH 4/4] golangci-lint: Silence new offenses Linters have picked up a couple of new offenses. Add new exclusion rules. --- .golangci.yml | 7 ++++++- controllers/openstackcluster_controller.go | 1 + pkg/cloud/services/networking/securitygroups.go | 1 - test/e2e/shared/exec.go | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 98a30c5100..3e17bf8644 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -157,8 +157,13 @@ issues: - linters: - revive - stylecheck - path: (test)/.*.go + path: (.+)_test\.go|(test)/.*.go text: should not use dot imports + - linters: + - revive + - stylecheck + path: (.+)_test\.go|(test)/.*.go + text: unused-parameter - linters: - revive path: test/e2e/shared/defaults.go diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index 08177fc9ed..9f57c473eb 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -566,6 +566,7 @@ func reconcileNetworkComponents(scope scope.Scope, cluster *clusterv1.Cluster, o // Set APIEndpoints so the Cluster API Cluster Controller can pull them openStackCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ Host: host, + //nolint:gosec // disable G115 Port: int32(apiServerPort), } } diff --git a/pkg/cloud/services/networking/securitygroups.go b/pkg/cloud/services/networking/securitygroups.go index ddea470128..5b65fb660a 100644 --- a/pkg/cloud/services/networking/securitygroups.go +++ b/pkg/cloud/services/networking/securitygroups.go @@ -71,7 +71,6 @@ func (s *Service) ReconcileSecurityGroups(openStackCluster *infrav1.OpenStackClu for k, desiredSecGroup := range desiredSecGroups { var err error observedSecGroups[k], err = s.getSecurityGroupByName(desiredSecGroup.Name) - if err != nil { return err } diff --git a/test/e2e/shared/exec.go b/test/e2e/shared/exec.go index df85fcbdd0..2e15239375 100644 --- a/test/e2e/shared/exec.go +++ b/test/e2e/shared/exec.go @@ -146,6 +146,7 @@ func executeCommand(ctx context.Context, p commandParameter) error { return fmt.Errorf("unable to send command %q: %s", "sudo "+p.cmd.cmd, err) } result := strings.TrimSuffix(stdoutBuf.String(), "\n") + "\n" + strings.TrimSuffix(stderrBuf.String(), "\n") + //nolint:gosec // disable G306 if err := os.WriteFile(logFile, []byte(result), os.ModePerm); err != nil { return fmt.Errorf("error writing log file: %s", err) }