Skip to content

go: fix golangci-lint errors#1814

Open
wainersm wants to merge 10 commits intoopenshift:develfrom
wainersm:golangci-lint-issues
Open

go: fix golangci-lint errors#1814
wainersm wants to merge 10 commits intoopenshift:develfrom
wainersm:golangci-lint-issues

Conversation

@wainersm
Copy link
Contributor

@wainersm wainersm commented Mar 6, 2026

- Description of the problem which is fixed/What is the use case

Currently we don't run any static analysis tool!

I've a plan to introduce some of those tools in our CI, and I wanted to start with golangci-lint.

- What I did

Ran make lint and with help of claude I delinted the entire project.

ps: our .golangci-lint file is configure to the mininum of mininum, that's why likely just a handful of errors were catch.

- How to verify it

make lint and it should return 0 errors.

@openshift-ci openshift-ci bot requested review from bpradipt and c3d March 6, 2026 21:07
@littlejawa
Copy link
Contributor

Hey @wainersm,
I've tried to run "make lint" and it failed. You mention GOPROXY, but how did you use it?
Asking Claude, it actually made me install an even newer version of golangci-lint (2.11.3) that is pre-built with go 1.25 and can run against our code. Should we do that instead?

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2026
@wainersm
Copy link
Contributor Author

2.11.3

@littlejawa commit 4669cc1 upgraded to golang 1.25 and I will be able to use a newer version of golangci-lint and hopefuly the GOPROXY hack won't be needed. I send a update soon.

Update golangci-lint from v2.0.2 to v2.11.3.1.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Fix error messages to start with lowercase letters per Go style guide.
This resolves 3 staticcheck ST1005 violations.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Remove duplicate import of k8s.io/apimachinery/pkg/api/errors package.
Use the k8serrors alias consistently throughout the file.

Resolves staticcheck ST1019 violation.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Simplify field access by removing redundant embedded field names:
- ns.ObjectMeta.Labels -> ns.Labels
- r.Client.Get/List/Delete -> r.Get/List/Delete
- req.NamespacedName.Name -> req.Name

Resolves several staticcheck QF1008 violations.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Convert multiple if-else if chains to tagged switch statements for
better readability and maintainability:
- confidential_handler.go: handler type selection
- image_generator.go: provider type selection

Resolves 2 staticcheck QF1003 violations.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Apply De Morgan's law to simplify complex boolean expression:
!(A || B) -> !A && !B

Makes the condition more readable and easier to understand.

Resolves staticcheck QF1001 violation.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Remove two functions that are never called:
- createMcFromFile in openshift_controller.go
- parseMachineConfigYAML in utils.go

Resolves 2 unused function violations.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Wrap all os.Setenv and os.Unsetenv calls with Expect().To(Succeed())
to properly handle error return values and resolve golangci-lint errcheck
violations.

Assisted-by: Claude
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
@wainersm wainersm force-pushed the golangci-lint-issues branch from f610a54 to 48aa973 Compare March 16, 2026 16:12
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2026
@wainersm
Copy link
Contributor Author

@littlejawa I bumped to golangci-lint 2.11.3 but it is pre-built with go 1.26 (unlike claude said):

$ golangci-lint --version
golangci-lint has version 2.11.3 built with go1.26.1 from 6008b81b on 2026-03-10T10:25:44Z 

That's the latest version. I don't think the version it has used is a problem.

I will work on a Github action to run it. So:

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 16, 2026
@wainersm
Copy link
Contributor Author

@littlejawa I just added a github workflow to run golangci-lint. I've using an action instead of calling make golangci-lint and I am getting an error that I cannot reproduce locally. Any idea?

@wainersm wainersm force-pushed the golangci-lint-issues branch 2 times, most recently from db0949f to e7bc8ea Compare March 16, 2026 20:28
The static-checks workflow is meant to trigger jobs on pull requests (or
manually) to run static checkers (e.g. golangci-lint, commit check, etc)
against the project.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
@wainersm wainersm force-pushed the golangci-lint-issues branch from e7bc8ea to c4e81d8 Compare March 16, 2026 20:31
The lint target runs golangci-lint that requires some controller code to
be generate, otherwise it make misleading reports. Hence, make lint to
depend on generate target.

Also fixed the target help message as yamllint is not executed.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
@wainersm
Copy link
Contributor Author

@littlejawa I just added a github workflow to run golangci-lint. I've using an action instead of calling make golangci-lint and I am getting an error that I cannot reproduce locally. Any idea?

I found the problem. It needs to run make generate to generate some sources for the controller. Fixed and the action is running fine.

@openshift-ci
Copy link

openshift-ci bot commented Mar 20, 2026

@wainersm: 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
ci/prow/ci-bundle-openshift-sandboxed-containers-operator-bundle 55897a8 link true /test ci-bundle-openshift-sandboxed-containers-operator-bundle

Full PR test history. Your PR dashboard.

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.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 20, 2026
@openshift-ci
Copy link

openshift-ci bot commented Mar 20, 2026

PR needs rebase.

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.

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants