Skip to content

Update golangci-lint to v2.11.4 and enable new linters#301

Open
saschagrunert wants to merge 1 commit intocri-o:mainfrom
saschagrunert:update-golangci-lint-v2.11.4
Open

Update golangci-lint to v2.11.4 and enable new linters#301
saschagrunert wants to merge 1 commit intocri-o:mainfrom
saschagrunert:update-golangci-lint-v2.11.4

Conversation

@saschagrunert
Copy link
Copy Markdown
Member

@saschagrunert saschagrunert commented Apr 30, 2026

/kind cleanup

What this PR does / why we need it:

Bumps golangci-lint from v2.0.1 to v2.11.4 and enables 13 new linters. Fixes all reported lint issues across the codebase.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?

None

Summary by CodeRabbit

  • Chores

    • Updated code linting configuration to enforce stricter quality standards across the codebase.
    • Upgraded golangci-lint tooling to the latest stable version for improved code analysis.
  • Refactor

    • Internal code improvements including structural reorganization and constant definitions for better maintainability and consistency.

@openshift-ci openshift-ci Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Apr 30, 2026
@openshift-ci openshift-ci Bot requested review from mrunalp and rajatchopra April 30, 2026 07:22
@openshift-ci openshift-ci Bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Apr 30, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saschagrunert

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@saschagrunert has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 45 minutes and 50 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7534d73b-c0df-4eef-a2c9-a9860e1cc9e2

📥 Commits

Reviewing files that changed from the base of the PR and between e2b9ae8 and 17751d7.

📒 Files selected for processing (8)
  • .golangci.yml
  • Makefile
  • pkg/ocicni/ocicni.go
  • pkg/ocicni/ocicni_test.go
  • pkg/ocicni/types.go
  • pkg/ocicni/types_unix.go
  • pkg/ocicni/util_linux.go
  • tools/ocicnitool/ocicnitool.go
📝 Walkthrough

Walkthrough

The pull request expands the active linter set in golangci-lint configuration, upgrades the tool version to v2.11.4, and updates codebase patterns to comply with new linters. Changes include context propagation for improved cancellation support, magic number extraction to named constants, JSON tag annotation suppressions for tagliatelle compliance, struct field reordering, and modernization of Go build tags.

Changes

Cohort / File(s) Summary
Linter Configuration
.golangci.yml, Makefile
Enables 12 new linters (cyclop, embeddedstructfieldcheck, funcorder, funlen, gocognit, godoclint, ireturn, iotamixing, mnd, modernize, tagliatelle, unqueryvet) with custom thresholds; updates whitespace linter from wsl to wsl_v5. Upgrades golangci-lint version from v2.0.1 to v2.11.4.
Context Propagation
pkg/ocicni/ocicni.go, pkg/ocicni/util_linux.go
Threads context.Context into getContainerDetails and Linux-specific IP retrieval commands via exec.CommandContext instead of exec.Command, enabling proper cancellation support.
Tagliatelle Linter Compliance
pkg/ocicni/ocicni.go, pkg/ocicni/ocicni_test.go, pkg/ocicni/types.go
Adds //nolint:tagliatelle suppressions to ContainerID, HostIP, PodAnnotations, and ValidAttachments JSON struct tags with inline rationale comments.
Code Refactoring & Organization
pkg/ocicni/ocicni.go, pkg/ocicni/types.go, pkg/ocicni/util_linux.go, tools/ocicnitool/ocicnitool.go
Extracts magic numbers to named constants (keyValuePairLen, minIPAddrFields, minLinkOutputLines, minLinkFields, minRequiredArgs); reorders NetResult struct fields to align embedded types; updates argument validation to use constants.
Build Tag Modernization
pkg/ocicni/types_unix.go, pkg/ocicni/util_linux.go
Removes legacy // +build directives, retaining only //go:build constraints for platform-specific compilation control.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 New linters hop in, with rules so fine,
Context flows through, where commands align,
Constants replace the magic numbers' dance,
Build tags grow modern at a glance,
Compliance achieved with a tidy prance! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Update golangci-lint to v2.11.4 and enable new linters' accurately summarizes the main changes in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 45 minutes and 50 seconds.

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

@saschagrunert saschagrunert force-pushed the update-golangci-lint-v2.11.4 branch from e2b9ae8 to b9bd8cb Compare April 30, 2026 07:24
@saschagrunert
Copy link
Copy Markdown
Member Author

@cri-o/cri-o-maintainers PTAL

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
tools/ocicnitool/ocicnitool.go (3)

14-23: ⚡ Quick win

Keep minRequiredArgs tightly coupled to positional arg indexing.

minRequiredArgs = 5 is used to guard the later indexing (flag.Args()[0]..[4]). The current value matches the switch dispatch + 4 positional fields, so it looks correct.

To reduce future drift, consider deriving it from the indexing intent (e.g., const minRequiredArgs = 1 /*cmd*/ + 4 /*pod_* */) or adding a short comment tying it to podNetwork fields.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/ocicnitool/ocicnitool.go` around lines 14 - 23, minRequiredArgs is
brittle because it's used to guard indexing into flag.Args()[0]..[4]; change it
so the intent is explicit by either computing it from the positional pieces
(e.g., minRequiredArgs := 1 /* cmd */ + 4 /* podNetwork fields */) or add a
short comment next to the constant tying it to the podNetwork positional fields
and the switch dispatch (referencing minRequiredArgs and flag.Args() usage) so
future edits won’t drift the required count.

102-119: ⚡ Quick win

Handle unknown commands explicitly (missing default in switch).

The switch flag.Args()[0] has cases for CmdAdd, CmdStatus, and CmdDel, but no default. If a user passes an unknown command, main() will fall through to the end and exit successfully without showing usage.

Add a default that calls flag.Usage() and exits non-zero.

🛠️ Proposed change
  switch flag.Args()[0] {
  case CmdAdd:
    results, err := plugin.SetUpPod(podNetwork)
    if err == nil {
      printSandboxResults(results)
    }
    exit(err)
  case CmdStatus:
    results, err := plugin.GetPodNetworkStatus(podNetwork)
    if err == nil {
      printSandboxResults(results)
    }
    exit(err)
  case CmdDel:
    exit(plugin.TearDownPod(podNetwork))
+ default:
+   flag.Usage()
+   os.Exit(2)
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/ocicnitool/ocicnitool.go` around lines 102 - 119, The switch over
flag.Args()[0] currently handles CmdAdd, CmdStatus, and CmdDel but lacks a
default branch, so unknown commands silently fall through; add a default case in
the switch (alongside the existing cases for CmdAdd, CmdStatus, CmdDel) that
calls flag.Usage() and then exits non-zero (e.g., exit(fmt.Errorf("unknown
command"))) so the program reports usage and returns an error when an
unrecognized command is passed.

68-72: ⚡ Quick win

Usage/validation failure currently exits with code 0.

When len(flag.Args()) < minRequiredArgs, the code calls flag.Usage() and then return, which makes the process exit with status 0. For CLI tools, “wrong invocation” typically should exit non-zero (commonly 2).

🛠️ Proposed change
  if len(flag.Args()) < minRequiredArgs {
    flag.Usage()
-
-    return
+    os.Exit(2)
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/ocicnitool/ocicnitool.go` around lines 68 - 72, The CLI currently calls
flag.Usage() and returns when len(flag.Args()) < minRequiredArgs, causing a zero
exit status; update the failure path in the same function (where flag.Args(),
minRequiredArgs and flag.Usage() are used) to call os.Exit(2) after printing
usage so the process exits non-zero on invalid invocation (importing os if not
already present).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/ocicni/types.go`:
- Around line 116-123: The exported struct NetResult had its exported fields
reordered, which can break downstream positional composite literals; revert the
struct field order to the original order (restore the exact sequence of
NetResult's fields so NetAttachment and Result appear in the original order),
ensure the NetResult definition uses the previous ordering of NetAttachment and
Result, and avoid reordering fields of exported structs in future changes (refer
to the NetResult type and its embedded NetAttachment and Result fields when
making the fix).

In `@pkg/ocicni/util_linux.go`:
- Around line 77-80: The error message reports the wrong line when link parsing
fails: parsing uses lines[1] but the fmt.Errorf references lines[0]; update the
error construction in the link-parse branch (the block that computes fields =
strings.Fields(lines[1]) and checks len(fields) < minLinkFields) to include
lines[1] (or otherwise the offending content) instead of lines[0] so the logged
content matches the parsed input; ensure the change is made where fields,
minLinkFields and the fmt.Errorf call are used.

---

Nitpick comments:
In `@tools/ocicnitool/ocicnitool.go`:
- Around line 14-23: minRequiredArgs is brittle because it's used to guard
indexing into flag.Args()[0]..[4]; change it so the intent is explicit by either
computing it from the positional pieces (e.g., minRequiredArgs := 1 /* cmd */ +
4 /* podNetwork fields */) or add a short comment next to the constant tying it
to the podNetwork positional fields and the switch dispatch (referencing
minRequiredArgs and flag.Args() usage) so future edits won’t drift the required
count.
- Around line 102-119: The switch over flag.Args()[0] currently handles CmdAdd,
CmdStatus, and CmdDel but lacks a default branch, so unknown commands silently
fall through; add a default case in the switch (alongside the existing cases for
CmdAdd, CmdStatus, CmdDel) that calls flag.Usage() and then exits non-zero
(e.g., exit(fmt.Errorf("unknown command"))) so the program reports usage and
returns an error when an unrecognized command is passed.
- Around line 68-72: The CLI currently calls flag.Usage() and returns when
len(flag.Args()) < minRequiredArgs, causing a zero exit status; update the
failure path in the same function (where flag.Args(), minRequiredArgs and
flag.Usage() are used) to call os.Exit(2) after printing usage so the process
exits non-zero on invalid invocation (importing os if not already present).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78021350-d11a-4ca5-a1c0-5bdd24add983

📥 Commits

Reviewing files that changed from the base of the PR and between 25c2c53 and e2b9ae8.

📒 Files selected for processing (8)
  • .golangci.yml
  • Makefile
  • pkg/ocicni/ocicni.go
  • pkg/ocicni/ocicni_test.go
  • pkg/ocicni/types.go
  • pkg/ocicni/types_unix.go
  • pkg/ocicni/util_linux.go
  • tools/ocicnitool/ocicnitool.go
💤 Files with no reviewable changes (1)
  • pkg/ocicni/types_unix.go

Comment thread pkg/ocicni/types.go
Comment thread pkg/ocicni/util_linux.go
@saschagrunert saschagrunert force-pushed the update-golangci-lint-v2.11.4 branch from b9bd8cb to 5e6c833 Compare April 30, 2026 07:32
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
@saschagrunert saschagrunert force-pushed the update-golangci-lint-v2.11.4 branch from 5e6c833 to 17751d7 Compare April 30, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant