From c67e946d279d70d72272a5d0934ff51d4c74bec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 8 Nov 2025 09:08:42 +0100 Subject: [PATCH 1/4] Show all issues from the linters Document the default selection and rearrange in alphabetical order, for easier comparison. --- .golangci.yaml | 9 +++++++-- Makefile | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 229d73d1433c..607008146542 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,15 +3,19 @@ run: timeout: 7m linters: enable: + - dogsled + - errcheck - gocritic - - revive + - govet - gocyclo + - ineffassign - misspell - nakedret + - revive - staticcheck - unconvert - unparam - - dogsled + - unused settings: staticcheck: checks: @@ -23,6 +27,7 @@ linters: - "-ST1020" - "-ST1021" - "-ST1022" + # Omit embedded fields from selector expression - "-QF1008" revive: diff --git a/Makefile b/Makefile index 00fd8b18257f..3a35426b899c 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,7 @@ GOLINT_JOBS ?= 4 GOLINT_GOGC ?= 100 # options for lint (golangci-lint) GOLINT_OPTIONS = \ + --max-issues-per-linter 0 --max-same-issues 0 \ --build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \ --config .golangci.yaml From c99ebd3d8e7d60deff7cd24799d9b1cf23b7e078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 8 Nov 2025 09:13:12 +0100 Subject: [PATCH 2/4] Enable formatters as well as linters Currently gofmt and goimports have separate targets, which means that they are forgotten for new changes. --- .golangci.yaml | 7 +++++++ cmd/minikube/cmd/config/view.go | 2 +- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/assets/addons_test.go | 2 +- pkg/minikube/assets/vm_assets.go | 2 +- pkg/minikube/download/licenses.go | 16 ++++++++-------- pkg/minikube/tunnel/route_windows_test.go | 6 ++++-- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 607008146542..0c46fa82122b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -170,3 +170,10 @@ linters: - path: '(.+)\.go$' text: "Error return value of `.*` is not checked" linter: errcheck +formatters: + enable: + - gofmt + - goimports + exclusions: + paths: + - third_party diff --git a/cmd/minikube/cmd/config/view.go b/cmd/minikube/cmd/config/view.go index 298d1e155360..836aef11fc79 100644 --- a/cmd/minikube/cmd/config/view.go +++ b/cmd/minikube/cmd/config/view.go @@ -40,7 +40,7 @@ type ViewTemplate struct { var configViewCmd = &cobra.Command{ Use: "view", Short: "Display values currently set in the minikube config file", - Long: `Display values currently set in the minikube config file. + Long: `Display values currently set in the minikube config file. The output format can be customized using the --format flag, which accepts a Go template. The config file is typically located at "~/.minikube/config/config.json".`, Run: func(_ *cobra.Command, _ []string) { diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 4aaa307d564b..8934f7ccc482 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -544,7 +544,7 @@ func updateDriver(driverName string) { } if errors.Is(err, auxdriver.ErrAuxDriverVersionNotinPath) { exit.Error(reason.DrvAuxNotHealthy, "Aux driver"+driverName, err) - } //if failed to update but not a fatal error, log it and continue (old version might still work) + } // if failed to update but not a fatal error, log it and continue (old version might still work) out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err}) } } diff --git a/pkg/minikube/assets/addons_test.go b/pkg/minikube/assets/addons_test.go index de5c995ab1a5..865c3cc4e718 100644 --- a/pkg/minikube/assets/addons_test.go +++ b/pkg/minikube/assets/addons_test.go @@ -45,7 +45,7 @@ func mapsEqual(a, b map[string]string) bool { func TestParseMapString(t *testing.T) { cases := map[string]map[string]string{ - "Aardvark=1,B=2,Cantaloupe=3": {"Aardvark": "1", "B": "2", "Cantaloupe": "3"}, + "Aardvark=1,B=2,Cantaloupe=3": {"Aardvark": "1", "B": "2", "Cantaloupe": "3"}, "A=,B=2,C=": {"A": "", "B": "2", "C": ""}, "": {}, "malformed,good=howdy,manyequals==,": {"good": "howdy"}, diff --git a/pkg/minikube/assets/vm_assets.go b/pkg/minikube/assets/vm_assets.go index f539a94882ef..b093fb6f043c 100644 --- a/pkg/minikube/assets/vm_assets.go +++ b/pkg/minikube/assets/vm_assets.go @@ -20,13 +20,13 @@ import ( "bytes" "embed" "fmt" - "text/template" "io" "os" "path" "path/filepath" "strconv" "strings" + "text/template" "time" "github.com/pkg/errors" diff --git a/pkg/minikube/download/licenses.go b/pkg/minikube/download/licenses.go index bcda1f6d292c..977f569015e0 100644 --- a/pkg/minikube/download/licenses.go +++ b/pkg/minikube/download/licenses.go @@ -67,15 +67,15 @@ func Licenses(dir string) error { return fmt.Errorf("failed to create temporary file: %v", err) } defer func() { - if err := os.Remove(tempFile.Name()); err != nil { - klog.Warningf("Failed to remove temp file %s: %v", tempFile.Name(), err) - } - }() + if err := os.Remove(tempFile.Name()); err != nil { + klog.Warningf("Failed to remove temp file %s: %v", tempFile.Name(), err) + } + }() defer func() { - if err := tempFile.Close(); err != nil { - klog.Warningf("Failed to close temp file %s: %v", tempFile.Name(), err) - } - }() + if err := tempFile.Close(); err != nil { + klog.Warningf("Failed to close temp file %s: %v", tempFile.Name(), err) + } + }() if _, err := io.Copy(tempFile, resp.Body); err != nil { return fmt.Errorf("failed to copy downloaded content from %s: %v", url, err) diff --git a/pkg/minikube/tunnel/route_windows_test.go b/pkg/minikube/tunnel/route_windows_test.go index 88843e4cb794..da42fdfe30a0 100644 --- a/pkg/minikube/tunnel/route_windows_test.go +++ b/pkg/minikube/tunnel/route_windows_test.go @@ -139,11 +139,13 @@ Persistent Routes: expectedRt := routingTable{ routingTableLine{ route: unsafeParseRoute("127.0.0.1", "10.96.0.0/12"), - line: " 10.96.0.0 255.240.0.0 127.0.0.1 127.0.0.1 281", + line: " 10.96.0.0 255.240.0.0" + + " 127.0.0.1 127.0.0.1 281", }, routingTableLine{ route: unsafeParseRoute("192.168.1.2", "10.211.55.0/24"), - line: " 10.211.55.0 255.255.255.0 192.168.1.2 10.211.55.3 281", + line: " 10.211.55.0 255.255.255.0" + + " 192.168.1.2 10.211.55.3 281", }, } if !reflect.DeepEqual(rt.String(), expectedRt.String()) { From f72b30ed54d3d28faa87a16484f0d11c4419c880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 8 Nov 2025 09:14:55 +0100 Subject: [PATCH 3/4] Allow using different golint config The list of enabled and disabled checks is not well maintained, so it stops all version upgrades. --- .golangci.max.yaml | 26 ++++++++++++++++++++++++++ .golangci.min.yaml | 26 ++++++++++++++++++++++++++ Makefile | 6 +++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .golangci.max.yaml create mode 100644 .golangci.min.yaml diff --git a/.golangci.max.yaml b/.golangci.max.yaml new file mode 100644 index 000000000000..1d6e8722df6f --- /dev/null +++ b/.golangci.max.yaml @@ -0,0 +1,26 @@ +version: "2" +linters: + enable: + - dogsled + - errcheck + - gocritic + - govet + - gocyclo + - ineffassign + - misspell + - nakedret + - revive + - staticcheck + - unconvert + - unparam + - unused + exclusions: + paths: + - third_party +formatters: + enable: + - gofmt + - goimports + exclusions: + paths: + - third_party diff --git a/.golangci.min.yaml b/.golangci.min.yaml new file mode 100644 index 000000000000..072bcbb45111 --- /dev/null +++ b/.golangci.min.yaml @@ -0,0 +1,26 @@ +version: "2" +linters: + enable: + - govet + - gocyclo + disable: + - errcheck + - staticcheck + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party + - '(.+)_test\.go' +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party diff --git a/Makefile b/Makefile index 3a35426b899c..1172918e6df3 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,10 @@ MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download # latest from https://github.com/golangci/golangci-lint/releases # update this only by running `make update-golint-version` GOLINT_VERSION ?= v2.1.5 +# see https://golangci-lint.run/docs/configuration/file/ for config details +GOLINT_CONFIG ?= .golangci.yaml +# Set this to --verbose to see details about the linters and formatters used +GOLINT_VERBOSE ?= # Limit number of default jobs, to avoid the CI builds running out of memory GOLINT_JOBS ?= 4 # see https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint @@ -83,7 +87,7 @@ GOLINT_GOGC ?= 100 GOLINT_OPTIONS = \ --max-issues-per-linter 0 --max-same-issues 0 \ --build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \ - --config .golangci.yaml + --config $(GOLINT_CONFIG) $(GOLINT_VERBOSE) export GO111MODULE := on From 561bf414edade7a2aae2d4f532e8a1ab5489636e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 8 Nov 2025 09:11:35 +0100 Subject: [PATCH 4/4] Bump golangci-lint version to 2.1.6 Newer versions are showing issues --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1172918e6df3..0838f60609b9 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download # latest from https://github.com/golangci/golangci-lint/releases # update this only by running `make update-golint-version` -GOLINT_VERSION ?= v2.1.5 +GOLINT_VERSION ?= v2.1.6 # see https://golangci-lint.run/docs/configuration/file/ for config details GOLINT_CONFIG ?= .golangci.yaml # Set this to --verbose to see details about the linters and formatters used