Skip to content

ROSAENG-61040 | refactor: remove github.com/pkg/errors#3421

Open
markirish wants to merge 1 commit into
openshift:masterfrom
markirish:ROSAENG-61040-remove-pkg-errors
Open

ROSAENG-61040 | refactor: remove github.com/pkg/errors#3421
markirish wants to merge 1 commit into
openshift:masterfrom
markirish:ROSAENG-61040-remove-pkg-errors

Conversation

@markirish

@markirish markirish commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Replace 3 errors.Wrapf calls with fmt.Errorf using the %w verb. The pkg/errors library is deprecated by its author in favor of standard error wrapping.

Detailed Description of the Issue

Our ROSA CLI project currently imports several third-party libraries that are only utilized in a single file (e.g., exclusively within a test file or for a single validation function). Relying on entire external dependencies for isolated use cases unnecessarily increases our security attack surface, complicates dependency management, and bloats the project.

This PR is part of that initiative to remove github.com/pkg/errors

Related Issues and PRs

Type of Change

  • feat - adds a new user-facing capability.
  • fix - resolves an incorrect behavior or bug.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

Behavior After This Change

How to Test (Step-by-Step)

Preconditions

Test Steps

  1. run make test

Expected Results

All tests pass

Proof of the Fix

All tests pass

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • make install-hooks has been run in this clone.
  • Tests were added/updated where appropriate.
  • I manually tested the change.
  • make test passes.
  • make lint passes.
  • make rosa passes.
  • Documentation or repo-local agent guidance was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting for machine pool upgrade validation, scheduling, and version selection.
    • Clarified error messages for invalid upgrade options, cluster readiness, machine pool identifiers, and missing node pools.
    • Preserved underlying error details for easier troubleshooting.

Replace 3 errors.Wrapf calls with fmt.Errorf using the %w verb.
The pkg/errors library is deprecated by its author in favor of
standard error wrapping.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The machine pool upgrade command replaces github.com/pkg/errors wrapping with fmt.Errorf, including wrapped scheduling and policy-building failures. Runtime validation, interactive prompt, and node pool version errors use revised wording. Tests update expected error substrings, and github.com/pkg/errors is classified as an indirect dependency in go.mod.

Possibly related PRs

  • openshift/rosa#3411: Modifies the same command to replace github.com/pkg/errors wrapping with fmt.Errorf.
🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately reflects the main change: removing github.com/pkg/errors via a refactor.
Description check ✅ Passed The description covers the issue, change, related issue, test steps, results, and checklist, matching the template well.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Stable And Deterministic Test Names ✅ Passed Touched Ginkgo titles are static literals (e.g. "Upgrade machine pool"); no dynamic values or generated identifiers appear.
Test Structure And Quality ✅ Passed Touched tests only adjust expected substrings; they stay single-purpose, use BeforeEach for runtime setup, and add no waits/resources. Style matches nearby tests.
Microshift Test Compatibility ✅ Passed Only existing unit-test assertions changed; no new Ginkgo e2e tests or MicroShift-unsafe APIs/features were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR only updates command logic and Ginkgo unit tests; no new e2e tests or multi-node/SNO assumptions were added.
Topology-Aware Scheduling Compatibility ✅ Passed PR only changes machinepool CLI error strings and dependency metadata; no manifests, controllers, or scheduling constraints were added.
Ote Binary Stdout Contract ✅ Passed Touched machinepool files only change error text/deps; their init/setup code doesn’t print to stdout, and no new process-level stdout writes were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PASS: The PR only changes a command, its unit tests, and go.mod; no new Ginkgo e2e tests or IPv4/external-connectivity assumptions were added.
No-Weak-Crypto ✅ Passed Touched files only adjust error handling/text and dependency bookkeeping; no MD5/SHA1/DES/RC4/3DES/Blowfish, ECB, custom crypto, or secret-comparison code was added.
Container-Privileges ✅ Passed The PR only changes Go error handling and go.mod; no container/K8s manifests or privilege settings were added or modified.
No-Sensitive-Data-In-Logs ✅ Passed No new sensitive-data logging found; changes only adjust error text and existing reporter output for cluster/machine-pool identifiers.
✨ 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

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

@openshift-ci
openshift-ci Bot requested review from amandahla and dustman9000 July 24, 2026 20:23
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/upgrade/machinepool/cmd.go`:
- Line 132: Use the registered flag name consistently: update the validation
error in cmd/upgrade/machinepool/cmd.go at lines 132-132 to reference
--allow-minor-version-updates, and update the expected substring in
cmd/upgrade/machinepool/cmd_test.go at lines 66-67 to match.
- Line 156: Update the five contextual error returns in the machinepool command,
including the one around “failed to get machine pools for hosted cluster” and
the corresponding locations, to wrap the underlying error with %w instead of
interpolating it with %s or %v. Preserve each existing message context and error
arguments so callers can use errors.Is and errors.As.
- Line 197: Update the error message in the machinepool upgrade command to
replace the grammatically incorrect “expected an choice” wording with “expected
a choice” or “expected a choice of versions to target,” while preserving the
existing error detail.
🪄 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: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 19777076-380e-4244-9d2c-6068111d99a4

📥 Commits

Reviewing files that changed from the base of the PR and between 8eff35d and 15a2726.

📒 Files selected for processing (3)
  • cmd/upgrade/machinepool/cmd.go
  • cmd/upgrade/machinepool/cmd_test.go
  • go.mod

// Check parameters preconditions
if currentUpgradeScheduling.Schedule == "" && currentUpgradeScheduling.AllowMinorVersionUpdates {
return fmt.Errorf("The '--allow-minor-version-upgrades' option needs to be used with --schedule")
return fmt.Errorf("the '--allow-minor-version-upgrades' option needs to be used with --schedule")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use --allow-minor-version-updates consistently.

The command registers and reads allow-minor-version-updates, but the validation error and its test expectation say --allow-minor-version-upgrades, producing an unusable remediation hint.

  • cmd/upgrade/machinepool/cmd.go#L132-L132: change the production error to --allow-minor-version-updates.
  • cmd/upgrade/machinepool/cmd_test.go#L66-L67: update the expected substring to the same registered flag name.
📍 Affects 2 files
  • cmd/upgrade/machinepool/cmd.go#L132-L132 (this comment)
  • cmd/upgrade/machinepool/cmd_test.go#L66-L67
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/upgrade/machinepool/cmd.go` at line 132, Use the registered flag name
consistently: update the validation error in cmd/upgrade/machinepool/cmd.go at
lines 132-132 to reference --allow-minor-version-updates, and update the
expected substring in cmd/upgrade/machinepool/cmd_test.go at lines 66-67 to
match.

_, exists, err := r.OCMClient.GetNodePool(cluster.ID(), machinePoolID)
if err != nil {
return fmt.Errorf("Failed to get machine pools for hosted cluster '%s': %v", clusterKey, err)
return fmt.Errorf("failed to get machine pools for hosted cluster '%s': %v", clusterKey, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve the underlying errors with %w.

%s and %v interpolate the cause into text, so callers cannot use errors.Is/errors.As and the original error context is lost. Replace these verbs with %w at all five locations.

As per coding guidelines, returned errors must be wrapped with context using %w; the PR objective also explicitly requires %w when replacing errors.Wrapf.

Proposed fix
-		return fmt.Errorf("failed to get machine pools for hosted cluster '%s': %v", clusterKey, err)
+		return fmt.Errorf("failed to get machine pools for hosted cluster '%s': %w", clusterKey, err)

-			return fmt.Errorf("expected an upgrade type: %s", err)
+			return fmt.Errorf("expected an upgrade type: %w", err)

-				return fmt.Errorf("expected an choice on the versions to target: %s", err)
+				return fmt.Errorf("expected a choice of versions to target: %w", err)

-			return "", fmt.Errorf("expected a valid machine pool version from interactive prompt: %s", err)
+			return "", fmt.Errorf("expected a valid machine pool version from interactive prompt: %w", err)

-		return "", fmt.Errorf("expected a valid machine pool version: %s", err)
+		return "", fmt.Errorf("expected a valid machine pool version: %w", err)

Also applies to: 186-186, 197-197, 362-362, 369-369

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/upgrade/machinepool/cmd.go` at line 156, Update the five contextual error
returns in the machinepool command, including the one around “failed to get
machine pools for hosted cluster” and the corresponding locations, to wrap the
underlying error with %w instead of interpolating it with %s or %v. Preserve
each existing message context and error arguments so callers can use errors.Is
and errors.As.

Source: Coding guidelines

})
if err != nil {
return fmt.Errorf("Expected an choice on the versions to target: %s", err)
return fmt.Errorf("expected an choice on the versions to target: %s", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the user-facing wording.

expected an choice is grammatically incorrect. Use expected a choice or expected a choice of versions to target.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/upgrade/machinepool/cmd.go` at line 197, Update the error message in the
machinepool upgrade command to replace the grammatically incorrect “expected an
choice” wording with “expected a choice” or “expected a choice of versions to
target,” while preserving the existing error detail.

Source: Coding guidelines

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@markirish: 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/govulncheck 15a2726 link false /test govulncheck
ci/prow/security 15a2726 link false /test security

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant