Skip to content

✨ (go/v4): upgrade golangci-lint to v2.12.1#5676

Open
dongjiang1989 wants to merge 7 commits into
kubernetes-sigs:masterfrom
dongjiang1989:golangci-linter-v2.12
Open

✨ (go/v4): upgrade golangci-lint to v2.12.1#5676
dongjiang1989 wants to merge 7 commits into
kubernetes-sigs:masterfrom
dongjiang1989:golangci-linter-v2.12

Conversation

@dongjiang1989
Copy link
Copy Markdown
Member

@dongjiang1989 dongjiang1989 commented May 6, 2026

Summary

  • Upgrade golangci-lint from v2.11.4 to v2.12.1 across all project files, CI workflows, and scaffolded templates
  • Add goconst linter configuration (ignore-tests: true, min-occurrences: 5) to reduce noise from test files
  • Replace manual reverse iteration with slices.Backward() in 3 files to satisfy the new goconst linter
  • Add //nolint:goconst for intentional string constants in options.go

Signed-off-by: dongjiang <dongjiang1989@126.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 6, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dongjiang1989
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 6, 2026
@dongjiang1989
Copy link
Copy Markdown
Member Author

/test pull-kubebuilder-e2e-k8s-1-36-0

Signed-off-by: dongjiang <dongjiang1989@126.com>
description: Checks Go logging calls for Kubernetes logging conventions.
goconst:
ignore-tests: true
min-occurrences: 5
Copy link
Copy Markdown
Contributor

@vitorfloriano vitorfloriano May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the goal of this config is to reduce noise from test files and we are already ignoring the tests, is min-ocurrences: 5 still necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min-ocurrences also applies to non-test files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...so the summary in the description is a bit misleading. In regards to this config, I favor explicitly adding no-lint directives to ocurrences than silently ignoring them. Also, a minimum of 5 seems a bit too much, doesn't it? It may solve problems at hand, but might also hide ocurrences in the long run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Agreed on both points.

• I’ll lower min-occurrences to 3.

• For specific cases, we’ll use explicit //nolint directives instead of silent ignores

WDYT? Default value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final offer: min of 2, take it or leave it!

Just kidding. Let's wait and hear what @camilamacedo86 has to say.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that we should ignore goconst
We need to fix the places where the error is raised instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I'll remove min-occurrences

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concern with the changes in the default scaffold.
What are the places that fails in the default scaffold?
Are too many? If not I think we should solve it out

Comment thread pkg/plugins/golang/options.go Outdated

if len(busybox.Status.Conditions) == 0 {
//nolint:goconst
meta.SetStatusCondition(&busybox.Status.Conditions, metav1.Condition{Type: typeAvailableBusybox, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the error here?
What is the value that the linter is asking for a const?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/25423812234/job/74572117344

goconst default value:

linters:
  settings:
    goconst:
      # Minimal length of string constant.
      # Default: 3
      min-len: 2
      # Minimum occurrences of constant string count to trigger issue.
      # Default: 3
      min-occurrences: 2
      # Look for existing constants matching the values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to check it properly.
How are we linting the samples?
Are we using the lint from samples or Kubebuilder config?
We should not change the config in the default scaffold.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @camilamacedo86
Using the lint config from samples; the lint rules in samples are broader in scope than those in golangci-linter default value.

@dongjiang1989
Copy link
Copy Markdown
Member Author

dongjiang1989 commented May 7, 2026

Hey @camilamacedo86 @vitorfloriano Please re-check it
Remove min-occurrences (use default value) done.

Signed-off-by: dongjiang <dongjiang1989@126.com>
description: Checks Go logging calls for Kubernetes logging conventions.
goconst:
ignore-tests: true
min-occurrences: 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should add it at all and change the golang ci config for the default scaffold, could we revert this change?

Copy link
Copy Markdown
Member Author

@dongjiang1989 dongjiang1989 May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm.... The lint rules in samples are broader in scope than those in golangci-linter default value(remove it). 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the sample because the default scaffold was changed.
We should not change the default scaffold config unless it is really required

Comment thread internal/cli/alpha/internal/generate.go Outdated
Comment thread internal/cli/alpha/internal/generate.go Outdated
Comment thread pkg/cli/root.go Outdated
Comment thread .golangci.yml
forbid-focus-container: true
forbid-spec-pollution: true
goconst:
ignore-tests: true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should add it here as well.
What are the failures ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it done.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so many errors:

......
pkg/plugins/golang/v4/api_test.go:120:14: string `Frigate` has 3 occurrences, make it a constant (goconst)
				Kind:    "Frigate",
				         ^
pkg/plugins/golang/v4/webhook_test.go:44:14: string `crew` has 7 occurrences, make it a constant (goconst)
				Group:   "crew",
				         ^
pkg/plugins/golang/v4/webhook_test.go:45:14: string `test.io` has 8 occurrences, make it a constant (goconst)
				Domain:  "test.io",
				         ^
pkg/plugins/golang/v4/webhook_test.go:47:14: string `Captain` has 4 occurrences, make it a constant (goconst)
				Kind:    "Captain",
				         ^
pkg/plugins/golang/v4/webhook_test.go:49:14: string `captains` has 3 occurrences, make it a constant (goconst)
			Plural:   "captains",
			          ^
pkg/plugins/golang/v4/webhook_test.go:122:15: string `ship` has 3 occurrences, make it a constant (goconst)
					Group:   "ship",
					         ^
pkg/plugins/golang/v4/webhook_test.go:125:15: string `Frigate` has 3 occurrences, make it a constant (goconst)
					Kind:    "Frigate",
					         ^
pkg/plugins/optional/helm/v1alpha/scaffolds/edit.go:269:48: string `rbac` has 3 occurrences, make it a constant (goconst)
		{"config/rbac", "dist/chart/templates/rbac", "rbac"},
		                                             ^
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/helpers.go:93:4: string `spec` has 4 occurrences, make it a constant (goconst)
		{"spec", "template", "spec", "containers"},
		 ^
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/templater_test.go:38:22: string `test-project` has 7 occurrences, make it a constant (goconst)
			detectedPrefix:   "test-project",
			                  ^
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/templater_test.go:3804:36: string `infrastructure` has 4 occurrences, make it a constant (goconst)
				"manager-role-infrastructure": "infrastructure",
				                               ^
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/templater_test.go:3805:36: string `users` has 3 occurrences, make it a constant (goconst)
				"manager-role-users":          "users",
				                               ^
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/templater_test.go:3909:5: string `manager-role` has 3 occurrences, make it a constant (goconst)
				"manager-role": "app-infrastructure",
				^
50 issues:
* goconst: 50
``

Signed-off-by: dongjiang <dongjiang1989@126.com>
Signed-off-by: dongjiang <dongjiang1989@126.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 9, 2026
Signed-off-by: dongjiang <dongjiang1989@126.com>
description: Checks Go logging calls for Kubernetes logging conventions.
goconst:
ignore-tests: true
min-occurrences: 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert it?
Then run make install and make generate ro regenerate all samples and etc?
We should not change the rules for what is scaffold by the tool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @camilamacedo86
Remove it many errors.

Do you mind if I remove it in the next PR to keep the scope of code changes smaller for this PR?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the golangci-lint version used by Kubebuilder and its scaffold/testdata projects, and updates lint configuration/templates to accommodate new linter behavior (notably goconst) and reduce repeated string literals.

Changes:

  • Bump golangci-lint from v2.11.4 to v2.12.1 across Makefiles, GitHub Actions, and scaffold/testdata configs.
  • Add/extend goconst configuration in scaffold/testdata/template .golangci.yml files and adjust code/templates to reduce repeated string literals.
  • Refactor a few spots to use shared constants and slices.Backward() for reverse scanning.

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Makefile Updates root tool version for golangci-lint.
.golangci.yml Enables/configures goconst at the repo level.
.github/workflows/verify-all.yml Updates golangci-lint version used in CI workflow.
.github/workflows/lint-sample.yml Updates golangci-lint version for sample linting.
pkg/plugins/golang/v4/scaffolds/init.go Updates scaffolded golangci-lint version constant.
pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go Updates scaffolded .golangci.yml template (adds goconst settings).
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_updater.go Uses slices.Backward() for reverse scanning in template updater.
pkg/plugins/golang/options.go Deduplicates repeated "k8s.io" strings via a constant.
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go Deduplicates condition Reason strings via constants in controller template.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/rbac.go Uses slices.Backward() for reverse scanning in YAML processing.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/manager.go Uses slices.Backward() for reverse scanning in indentation detection.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/helpers.go Deduplicates pod-template field paths used for container-name extraction.
pkg/plugins/optional/helm/v1alpha/scaffolds/edit.go Replaces repeated subdir strings with constants.
pkg/machinery/marker.go Centralizes .go extension as goExt constant for reuse.
pkg/machinery/scaffold.go Uses goExt constant when deciding to run imports.Process.
pkg/cli/cli.go Centralizes go plugin key strings as constants for reuse.
pkg/cli/root.go Uses constants for plugin filtering logic in help output.
internal/cli/alpha/internal/generate.go Replaces repeated subcommand/flag/plugin-key strings with constants.
internal/cli/alpha/internal/update/helpers/open_gh_issue.go Replaces repeated critical-filename strings with constants.
testdata/project-v4/Makefile Updates golangci-lint version in v4 testdata Makefile.
testdata/project-v4/.golangci.yml Adds goconst settings to v4 testdata config.
testdata/project-v4/.custom-gcl.yml Updates custom golangci-lint plugin config version.
testdata/project-v4-with-plugins/Makefile Updates golangci-lint version in plugins testdata Makefile.
testdata/project-v4-with-plugins/.golangci.yml Adds goconst settings to plugins testdata config.
testdata/project-v4-with-plugins/.custom-gcl.yml Updates custom golangci-lint plugin config version.
testdata/project-v4-with-plugins/internal/controller/memcached_controller.go Deduplicates condition Reason strings via constants in testdata controller.
testdata/project-v4-with-plugins/internal/controller/busybox_controller.go Deduplicates condition Reason strings via constants in testdata controller.
testdata/project-v4-multigroup/Makefile Updates golangci-lint version in multigroup testdata Makefile.
testdata/project-v4-multigroup/.golangci.yml Adds goconst settings to multigroup testdata config.
testdata/project-v4-multigroup/.custom-gcl.yml Updates custom golangci-lint plugin config version.
testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller.go Deduplicates condition Reason strings via constants in multigroup testdata controller.
testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go Deduplicates condition Reason strings via constants in multigroup testdata controller.
docs/book/src/getting-started/testdata/project/Makefile Updates golangci-lint version in docs testdata Makefile.
docs/book/src/getting-started/testdata/project/.golangci.yml Adds goconst settings to docs testdata config.
docs/book/src/getting-started/testdata/project/.custom-gcl.yml Updates custom golangci-lint plugin config version.
docs/book/src/cronjob-tutorial/testdata/project/Makefile Updates golangci-lint version in docs testdata Makefile.
docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml Adds goconst settings to docs testdata config.
docs/book/src/cronjob-tutorial/testdata/project/.custom-gcl.yml Updates custom golangci-lint plugin config version.
docs/book/src/multiversion-tutorial/testdata/project/Makefile Updates golangci-lint version in docs testdata Makefile.
docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml Adds goconst settings to docs testdata config.
docs/book/src/multiversion-tutorial/testdata/project/.custom-gcl.yml Updates custom golangci-lint plugin config version.

Comment thread .golangci.yml
Comment thread pkg/cli/root.go Outdated
Comment thread internal/cli/alpha/internal/update/helpers/open_gh_issue.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.

Comment thread .golangci.yml
Comment thread internal/cli/alpha/internal/update/helpers/open_gh_issue.go
Signed-off-by: dongjiang <dongjiang1989@126.com>
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@dongjiang1989: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-36-0 e264b9b link true /test pull-kubebuilder-e2e-k8s-1-36-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants