Skip to content

modcheck: arg parsing, custom target, downgrade intelligence#2915

Open
2uasimojo wants to merge 3 commits into
openshift:masterfrom
2uasimojo:modcheck-args
Open

modcheck: arg parsing, custom target, downgrade intelligence#2915
2uasimojo wants to merge 3 commits into
openshift:masterfrom
2uasimojo:modcheck-args

Conversation

@2uasimojo
Copy link
Copy Markdown
Member

@2uasimojo 2uasimojo commented May 29, 2026

hack/modcheck.go grows:

  • Real option parsing
  • --fix replaces -f (same functionality)
  • --gomod path/to/go.mod to designate a target other than apis/go.mod (the default)
  • Ability to detect whether fixing a mismatch would result in an upgrade or downgrade. If the latter, refuse to fix it by default. --allow-downgrade to override and fix it anyway.

Co-Authored-By: claude

Summary by CodeRabbit

  • Chores
    • Modernized module dependency management command with improved flag-based argument parsing for better control over operations.
    • Enhanced version comparison logic for improved handling of dependency upgrades and downgrades.

2uasimojo added 3 commits May 29, 2026 16:23
The `modcheck` utility is updated to do real argument parsing. The
erstwhile `-f` option ("fix `require` discrepancies in apis/go.mod") is
now spelled `--fix` (or, apparently `-fix`, because golang) but
otherwise functions identically. As a bonus, `--help` and similar
options prints a nice usage message.

Co-Authored-By: claude
Add the ability to check different go.mod files (like test/ote/go.mod)
by adding a `--gomod` option to `modcheck` whereby a path to the
secondary go.mod file can be provided. This defaults to `apis/go.mod`,
so the default behavior is unchanged.

Co-Authored-By: claude
Previously `modcheck --fix` would blat the root go.mod's semver onto the
target go.mod no matter what. With this change, it will by default
refuse to downgrade the target dep. To override this default behavior
and allow downgrades, a new `--allow-downgrade` option is available.

To provide visual support of this new intelligence, the `XX` prefix for
mismatches is now either `<<` (downgrade) or `>>` (upgrade).

Co-Authored-By: claude
@2uasimojo
Copy link
Copy Markdown
Member Author

/assign @suhanime

@2uasimojo
Copy link
Copy Markdown
Member Author

/cc @miyadav

@openshift-ci openshift-ci Bot requested a review from miyadav May 29, 2026 22:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

📝 Walkthrough

Walkthrough

The module checker script (hack/modcheck.go) is refactored to use proper flag-based argument parsing with a new options struct, replacing ad-hoc -f handling. The Makefile invocation is updated to use --fix. Reconciliation logic is reorganized: a new compareVersions helper handles version normalization and comparison, while a new (*options).processRequire method moves require-reconciliation logic into an options-bound method that tracks changes and supports --allow-downgrade behavior. The cmpExclude and cmpReplace functions are updated to use the new comparison indicators.

Changes

Module Checker Flag Parsing and Reconciliation Refactor

Layer / File(s) Summary
Entry point and flag parsing
Makefile, hack/modcheck.go
The modfix target now invokes modcheck.go with --fix instead of -f. Main control flow is refactored to parse --fix, --gomod, and --allow-downgrade flags into an options struct, read both root and target go.mod files, run reconciliation methods, apply Exclude/Replace checks, and exit with status codes reflecting sync/fix/error state.
Require reconciliation and version comparison
hack/modcheck.go
A new compareVersions(v1, v2) helper normalizes semver prefixes and returns both the numeric comparison result and a direction indicator string (>>, <<, ==). A new (*options).processRequire method is introduced to reconcile require version mismatches, respecting --fix and --allow-downgrade flags, mutating the target file, and returning (allInSync, madeChanges, error) status.
Exclude and Replace comparison updates
hack/modcheck.go
The cmpExclude and cmpReplace functions are updated to use the direction indicators from compareVersions when reporting version differences, removing the prior tight coupling to doFix mode semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

In the garden of Go modules, where versions must align,
A clever refactor brings structure divine—
Flags now parse cleanly, comparisons shine bright,
With methods well-ordered, the checker sets things right! 🐇✨

🚥 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 accurately captures the three main enhancements: improved argument parsing, custom target support via --gomod, and downgrade detection intelligence.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Command failed


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

@openshift-ci openshift-ci Bot requested review from jstuever and suhanime May 29, 2026 22:43
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 29, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 2uasimojo

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 May 29, 2026
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: 1

🧹 Nitpick comments (1)
hack/modcheck.go (1)

280-280: 💤 Low value

Consider improving replacement mismatch output formatting.

The format string uses %s to print replacement structs, which will output Go's default struct format like {newpath:foo newver:1.2.3}. While functional, a more user-friendly format would improve readability.

Optional improvement
-			fmt.Printf("%s replace %s: root(%s) target(%s)\n", indicator, path, rootrepl, targetrepl)
+			fmt.Printf("%s replace %s: root(%s@%s) target(%s@%s)\n", 
+				indicator, path, rootrepl.newpath, rootrepl.newver, targetrepl.newpath, targetrepl.newver)
🤖 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 `@hack/modcheck.go` at line 280, The replace mismatch print currently uses "%s"
to print the replacement structs (rootrepl and targetrepl) which yields raw Go
struct formatting; update the fmt.Printf call to output a clearer, user-friendly
string by interpolating the struct fields (e.g., newpath and newver or whichever
field names exist on the replacement type) instead of the whole struct, e.g.,
build a format like "%s replace %s: root(%s@%s) target(%s@%s)\n" and pass
indicator, path, rootrepl.<field>, rootrepl.<field>, targetrepl.<field>,
targetrepl.<field> using the actual field names from the replacement type.
🤖 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 `@hack/modcheck.go`:
- Line 74: The os.WriteFile call using opts.gomod is passing mode 0 which
creates an inaccessible file; change the file mode to a sensible default (e.g.
owner read/write and group/other read) when writing the module file so it is
readable by subsequent operations—update the os.WriteFile(opts.gomod, b, 0)
invocation to use a proper FileMode like 0644 (or a project-appropriate
permission constant) and ensure any surrounding error handling in the same
function preserves/report the error as before.

---

Nitpick comments:
In `@hack/modcheck.go`:
- Line 280: The replace mismatch print currently uses "%s" to print the
replacement structs (rootrepl and targetrepl) which yields raw Go struct
formatting; update the fmt.Printf call to output a clearer, user-friendly string
by interpolating the struct fields (e.g., newpath and newver or whichever field
names exist on the replacement type) instead of the whole struct, e.g., build a
format like "%s replace %s: root(%s@%s) target(%s@%s)\n" and pass indicator,
path, rootrepl.<field>, rootrepl.<field>, targetrepl.<field>, targetrepl.<field>
using the actual field names from the replacement type.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: dd55bbc1-8803-46ad-a5d7-f7f4eb90c29c

📥 Commits

Reviewing files that changed from the base of the PR and between db81e46 and a455995.

📒 Files selected for processing (2)
  • Makefile
  • hack/modcheck.go

Comment thread hack/modcheck.go
}
if err = os.WriteFile(apispath, b, 0); err != nil {
fmt.Printf("Failed to write modified %s: %s\n", apispath, err)
if err = os.WriteFile(opts.gomod, b, 0); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: File permissions must not be zero.

os.WriteFile is called with permissions 0, which creates a file with no read, write, or execute permissions for anyone. This will make the file inaccessible and likely cause failures in subsequent operations.

🔧 Proposed fix
-		if err = os.WriteFile(opts.gomod, b, 0); err != nil {
+		if err = os.WriteFile(opts.gomod, b, 0644); err != nil {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err = os.WriteFile(opts.gomod, b, 0); err != nil {
if err = os.WriteFile(opts.gomod, b, 0644); err != nil {
🤖 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 `@hack/modcheck.go` at line 74, The os.WriteFile call using opts.gomod is
passing mode 0 which creates an inaccessible file; change the file mode to a
sensible default (e.g. owner read/write and group/other read) when writing the
module file so it is readable by subsequent operations—update the
os.WriteFile(opts.gomod, b, 0) invocation to use a proper FileMode like 0644 (or
a project-appropriate permission constant) and ensure any surrounding error
handling in the same function preserves/report the error as before.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.39%. Comparing base (db81e46) to head (a455995).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2915   +/-   ##
=======================================
  Coverage   50.39%   50.39%           
=======================================
  Files         281      281           
  Lines       34368    34368           
=======================================
  Hits        17320    17320           
  Misses      15696    15696           
  Partials     1352     1352           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 30, 2026

@2uasimojo: 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/verify a455995 link true /test verify
ci/prow/security a455995 link true /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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants