Skip to content

Upgrade golangci-lint from v1 to v2#1279

Open
sebrandon1 wants to merge 2 commits intoopenshift:mainfrom
sebrandon1:golangci-lint-v2-upgrade
Open

Upgrade golangci-lint from v1 to v2#1279
sebrandon1 wants to merge 2 commits intoopenshift:mainfrom
sebrandon1:golangci-lint-v2-upgrade

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented Jan 16, 2026

Summary

  • Update golangci-lint from v1.64.8 to v2.0.2
  • Migrate .golangci.yaml to v2 format

Changes Made

  • Makefile: Updated version variable
  • .golangci.yaml: Converted to v2 format
    • Added version: "2" declaration
    • Moved gofumpt to formatters.enable

Test plan

  • CI linting passes with golangci-lint v2
  • No new linting errors introduced

Tracking: redhat-best-practices-for-k8s/telco-bot#49

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated golangci-lint to v2.11.4 and enabled stricter linting rules for improved code quality.
  • Refactor

    • Standardized Kubernetes API field access patterns across codebase for consistency.
    • Consolidated type aliases and imports to reduce duplication.
    • Updated internal test code to align with refactored implementations.
  • Style

    • Standardized error message formatting for consistency.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jan 16, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sebrandon1
Once this PR has been reviewed and has the lgtm label, please assign ricardomaraschini 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

@flavianmissi
Copy link
Copy Markdown
Member

thanks for this @sebrandon1 !
The verify job is failing with the following:

Error: unknown linters: 'gosimple', run 'golangci-lint help linters' to see the list of supported linters
Failed executing command with error: unknown linters: 'gosimple', run 'golangci-lint help linters' to see the list of supported linters

I see that gosimple was working fine with golanci-lint v1... do you know what might have happened to make it so that it cannot be found on v2?

@sebrandon1 sebrandon1 force-pushed the golangci-lint-v2-upgrade branch from 45b0dd8 to ccf9175 Compare February 23, 2026 15:15
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2026
@sebrandon1
Copy link
Copy Markdown
Member Author

Thanks for catching that @flavianmissi! In golangci-lint v2, gosimple was merged into staticcheck and is no longer a standalone linter. I've pushed a fix removing it from the config — since staticcheck is already enabled, all the gosimple checks are still covered. CI should be green now.

@sebrandon1 sebrandon1 force-pushed the golangci-lint-v2-upgrade branch from ccf9175 to 92dc720 Compare February 23, 2026 15:47
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2026
@sebrandon1 sebrandon1 force-pushed the golangci-lint-v2-upgrade branch from 92dc720 to 61a59f8 Compare February 23, 2026 15:50
- Update GOLANGCI_LINT_VERSION from v1.64.8 to v2.0.2
- Migrate .golangci.yaml to v2 format:
  - Add version: "2" declaration
  - Move gofumpt to formatters.enable section
  - Remove gosimple linter (merged into staticcheck in v2)

Tracking: redhat-best-practices-for-k8s/telco-bot#49
- Update golangci-lint version from v2.11.3 to v2.11.4 in Makefile
- Remove staticcheck exclusions for QF1001, QF1004, QF1008, ST1005, ST1012, ST1019 and enable errcheck linter
- Fix duplicate imports by consolidating to single aliases (ST1019)
- Remove unnecessary embedded field selectors (QF1008)
- Use strings.ReplaceAll instead of strings.Replace with -1 (QF1004)
- Apply De Morgan law simplification (QF1001)
- Lowercase error strings per Go conventions (ST1005)
- Rename UserTagsNotDefined to ErrUserTagsNotDefined (ST1012)
@sebrandon1 sebrandon1 force-pushed the golangci-lint-v2-upgrade branch from 61a59f8 to cc45416 Compare April 17, 2026 13:10
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: afdf177a-1d7c-4718-8dac-37dc7f32ed8f

📥 Commits

Reviewing files that changed from the base of the PR and between 5c4d186 and cc45416.

📒 Files selected for processing (29)
  • .golangci.yaml
  • Makefile
  • pkg/client/clients.go
  • pkg/client/listers.go
  • pkg/operator/bootstrap.go
  • pkg/operator/complete.go
  • pkg/operator/controller.go
  • pkg/operator/controller_test.go
  • pkg/operator/controllerimagepruner.go
  • pkg/operator/finalizer.go
  • pkg/operator/imageconfig.go
  • pkg/operator/status.go
  • pkg/resource/azurepathfixjob.go
  • pkg/resource/caconfig.go
  • pkg/resource/clusteroperator.go
  • pkg/resource/deployment.go
  • pkg/resource/imageregistryca.go
  • pkg/resource/podtemplatespec.go
  • pkg/resource/podtemplatespec_test.go
  • pkg/resource/prunercronjob.go
  • pkg/resource/service.go
  • pkg/storage/azure/azureclient/azureclient.go
  • pkg/storage/gcs/gcp_labels_tags.go
  • pkg/storage/gcs/gcp_labels_tags_test.go
  • pkg/storage/swift/swift.go
  • test/e2e/aws_test.go
  • test/e2e/azure_test.go
  • test/e2e/gcs_test.go
  • test/framework/testenv.go

Walkthrough

This pull request consolidates Kubernetes API type imports, refactors direct field access patterns on Kubernetes resources to bypass embedded ObjectMeta, updates string manipulation APIs, renames a sentinel error, and adjusts linter configuration. The changes affect approximately 30 files but maintain consistent, mechanical patterns across the codebase.

Changes

Cohort / File(s) Summary
Build & Linter Configuration
.golangci.yaml, Makefile
Upgrade golangci-lint from v2.11.3 to v2.11.4; enable errcheck linter and remove previously disabled staticcheck rules (QF1001, QF1004, QF1008, ST1005, ST1012, ST1019).
API Imports & Type Consolidation
pkg/client/clients.go, pkg/client/listers.go, pkg/resource/prunercronjob.go, pkg/operator/status.go
Replace deprecated/aliased Kubernetes API imports with standard equivalents: jobset.BatchV1Interfacebatchset.BatchV1Interface, kjoblisters.*kbatchlisters.*, batchapi.*batchv1.*, removing now-unused import aliases.
ObjectMeta Field Access Refactoring
pkg/operator/complete.go, pkg/operator/controller.go, pkg/operator/finalizer.go, pkg/resource/deployment.go, pkg/resource/service.go, pkg/operator/controllerimagepruner.go
Access resource fields (Finalizers, DeletionTimestamp, Annotations, Generation) directly from the resource instead of via the embedded ObjectMeta field.
Lister Field Structure Update
pkg/operator/bootstrap.go, test/e2e/aws_test.go, test/e2e/azure_test.go, test/e2e/gcs_test.go
Update calls to util.GetInfrastructure to use listers.Infrastructures directly instead of listers.StorageListers.Infrastructures.
String Replacement API Updates
pkg/resource/caconfig.go, pkg/resource/imageregistryca.go, pkg/storage/azure/azureclient/azureclient.go, pkg/storage/swift/swift.go
Replace strings.Replace(..., -1) with strings.ReplaceAll(...) for cleaner API usage.
Error Handling & Messages
pkg/storage/gcs/gcp_labels_tags.go, pkg/storage/gcs/gcp_labels_tags_test.go
Rename exported sentinel error UserTagsNotDefinedErrUserTagsNotDefined; update error message capitalization to lowercase ("Unknown authentication method""unknown authentication method"; "Incorrect Auth URL""incorrect auth URL").
Import Consolidation & API Type Updates
pkg/resource/azurepathfixjob.go, pkg/operator/imageconfig.go, pkg/resource/clusteroperator.go, pkg/resource/podtemplatespec.go, pkg/resource/podtemplatespec_test.go, test/framework/testenv.go
Remove duplicate/unused imports (kcorev1, configapi, operatorapi, metaapi); update type references to use consolidated imports (corev1, configv1, operatorv1, metav1).
Test API Updates
pkg/operator/controller_test.go
Update test fixtures to use imageregistryv1.* types instead of the removed imageregistryapiv1.* imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 9 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main objective: upgrading golangci-lint from v1 to v2, which is the primary driver for all subsequent code changes and lint fixes throughout the changeset.
Stable And Deterministic Test Names ✅ Passed PR does not introduce or modify any Ginkgo test names; all modified test files use standard Go testing with static, descriptive test names.
Test Structure And Quality ✅ Passed The PR summary mentions test file modifications, but these test files do not exist in the repository. No actual test code was modified.
Microshift Test Compatibility ✅ Passed PR does not add any new Ginkgo e2e tests; only updates existing standard Go tests as part of golangci-lint v2 upgrade refactoring.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR does not add new Ginkgo e2e tests; modifications update existing tests with symmetric line changes, not new test logic or Ginkgo blocks.
Topology-Aware Scheduling Compatibility ✅ Passed Pull request contains only linter configuration updates, API type migrations, and code cleanup with no topology-aware scheduling incompatibilities introduced.
Ote Binary Stdout Contract ✅ Passed No process-level code modifications detected. Main binaries remain unchanged with proper logging. The testenv.go refactoring does not affect stdout behavior.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR does not add any new Ginkgo e2e tests, only modifies existing test functions with refactored argument passing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 17, 2026

@sebrandon1: The following tests 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/e2e-vsphere ccf9175 link false /test e2e-vsphere
ci/prow/e2e-vsphere-operator ccf9175 link true /test e2e-vsphere-operator
ci/prow/e2e-openstack cc45416 link false /test e2e-openstack
ci/prow/e2e-gcp-operator cc45416 link false /test e2e-gcp-operator

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants