Skip to content

CNF-23386: mockgen deprecated: use uber-go/mock instead#271

Open
sebrandon1 wants to merge 1 commit into
openshift:masterfrom
sebrandon1:mockgen_deprecation
Open

CNF-23386: mockgen deprecated: use uber-go/mock instead#271
sebrandon1 wants to merge 1 commit into
openshift:masterfrom
sebrandon1:mockgen_deprecation

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented Nov 13, 2025

https://github.com/golang/mock is marked as archived as of June 27, 2023. They recommend using go.uber.org/mock.

This PR attempts to change the dependency to one that is maintained.

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

Summary by CodeRabbit

  • Chores

    • Switched mocking tooling to Uber’s mockgen and bumped the Go toolchain to 1.25.8; removed the previous mock dependency.
  • Documentation

    • Updated testing docs and install instructions to reference the new mockgen coordinates and installation command.
  • Tests

    • Regenerated mocks to align with the new generator; some mocks include new internal marker fields and a few mock signatures were adjusted.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 32.25806% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.34%. Comparing base (aa5f2cf) to head (a21f9c5).

Files with missing lines Patch % Lines
pkg/util/mocks/cr-client.go 34.04% 27 Missing and 4 partials ⚠️
pkg/util/mocks/status-writer.go 26.66% 10 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (32.25%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #271   +/-   ##
=======================================
  Coverage   58.34%   58.34%           
=======================================
  Files          26       26           
  Lines        1942     1942           
=======================================
  Hits         1133     1133           
  Misses        731      731           
  Partials       78       78           
Files with missing lines Coverage Δ
...ontrollers/projectclaim/projectclaim_controller.go 64.86% <ø> (ø)
pkg/condition/conditions.go 83.87% <ø> (ø)
pkg/gcpclient/client.go 0.00% <ø> (ø)
pkg/util/mocks/condition/conditions.go 100.00% <ø> (ø)
pkg/util/mocks/gcpclient/client.go 82.75% <ø> (ø)
.../util/mocks/projectclaim/customeresourceadapter.go 78.04% <ø> (ø)
pkg/util/mocks/status-writer.go 38.09% <26.66%> (ø)
pkg/util/mocks/cr-client.go 38.57% <34.04%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from b036341 to c29b305 Compare March 20, 2026 19:44
@sebrandon1 sebrandon1 changed the title mockgen deprecated: use uber-go/mock instead CNF-23386: mockgen deprecated: use uber-go/mock instead Apr 30, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 30, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 30, 2026

@sebrandon1: This pull request references CNF-23386 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

https://github.com/golang/mock is marked as archived as of June 27, 2023. They recommend using go.uber.org/mock.

This PR attempts to change the dependency to one that is maintained.

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

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 openshift-eng/jira-lifecycle-plugin repository.

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from c29b305 to b733de2 Compare May 5, 2026 22:35
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 8a3f63d8-9878-42f1-a2c8-a9c7fd4571ba

📥 Commits

Reviewing files that changed from the base of the PR and between e6ccc93 and a21f9c5.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • config/config.go
  • controllers/projectclaim/projectclaim_controller.go
  • docs/testing.md
  • go.mod
  • pkg/condition/conditions.go
  • pkg/gcpclient/client.go
  • pkg/util/mocks/condition/conditions.go
  • pkg/util/mocks/cr-client.go
  • pkg/util/mocks/doc.go
  • pkg/util/mocks/gcpclient/client.go
  • pkg/util/mocks/generate.go
  • pkg/util/mocks/projectclaim/customeresourceadapter.go
  • pkg/util/mocks/status-writer.go
💤 Files with no reviewable changes (1)
  • go.mod
✅ Files skipped from review due to trivial changes (8)
  • pkg/util/mocks/projectclaim/customeresourceadapter.go
  • config/config.go
  • pkg/util/mocks/gcpclient/client.go
  • pkg/condition/conditions.go
  • controllers/projectclaim/projectclaim_controller.go
  • pkg/util/mocks/doc.go
  • pkg/util/mocks/status-writer.go
  • pkg/util/mocks/cr-client.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/testing.md
  • pkg/util/mocks/condition/conditions.go
  • pkg/util/mocks/generate.go
  • pkg/gcpclient/client.go

Walkthrough

Switch mock tooling to go.uber.org/mock: update go.mod and docs, change //go:generate lines to run mockgen via go run, and regenerate mock files (added internal marker fields, adjusted signatures/varargs); plus a small config whitespace normalization.

Changes

Mock Generation Tool Migration

Layer / File(s) Summary
Go toolchain, docs, and small config tweak
go.mod, docs/testing.md, config/config.go, pkg/util/mocks/doc.go, pkg/util/mocks/generate.go
Updated module go directive to 1.25.8 and removed github.com/golang/mock from require; docs now reference go.uber.org/mock and use go install go.uber.org/mock/mockgen@v0.6.0; three const whitespace normalizations and blank-import target updated.
go:generate directives
controllers/projectclaim/projectclaim_controller.go, pkg/condition/conditions.go, pkg/gcpclient/client.go
Rewrote //go:generate lines to invoke mockgen via go run go.uber.org/mock/mockgen.
Regenerated mocks and codegen shape changes
pkg/util/mocks/*, pkg/util/mocks/cr-client.go, pkg/util/mocks/status-writer.go, pkg/util/mocks/gcpclient/client.go, pkg/util/mocks/projectclaim/customeresourceadapter.go
Regenerated mock files: added unexported isgomock struct{} fields, updated imports and MockClient.Get key type to client.ObjectKey, and regenerated recorder/base methods to use named parameters and rebuilt varargs; MockStatusWriter methods/recorders now use explicit typed parameter names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 10

❌ Failed checks (10 inconclusive)

Check name Status Explanation Resolution
Stable And Deterministic Test Names ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Test Structure And Quality ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Microshift Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Single Node Openshift (Sno) Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Topology-Aware Scheduling Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ote Binary Stdout Contract ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ipv6 And Disconnected Network Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Weak-Crypto ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Container-Privileges ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Sensitive-Data-In-Logs ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating from the deprecated golang/mock library to the maintained uber-go/mock alternative, with a reference to the tracking issue.
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.

✏️ 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

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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

@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from b733de2 to 3cee832 Compare May 20, 2026 15:27
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch 2 times, most recently from 23c2388 to e6ccc93 Compare May 29, 2026 16:32
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 29, 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 nikokolas3270 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

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

🤖 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 `@pkg/util/mocks/generate.go`:
- Around line 10-11: The go:generate directives in pkg/util/mocks/generate.go
currently call go.uber.org/mock/mockgen without a version which allows the
generator to drift; update the two directives (the lines invoking mockgen for
Client and StatusWriter) to pin a specific mockgen module version (e.g., append
`@v0.6.0` to go.uber.org/mock/mockgen) and make the same pinning change wherever
else mockgen is invoked (e.g., pkg/condition/conditions.go) so generated mocks
remain reproducible and consistent with the repo's intended generator version.
🪄 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: Enterprise

Run ID: 718b54c6-cb76-41b5-a370-8766127eafc1

📥 Commits

Reviewing files that changed from the base of the PR and between 3cee832 and e6ccc93.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • config/config.go
  • controllers/projectclaim/projectclaim_controller.go
  • docs/testing.md
  • go.mod
  • pkg/condition/conditions.go
  • pkg/gcpclient/client.go
  • pkg/util/mocks/condition/conditions.go
  • pkg/util/mocks/cr-client.go
  • pkg/util/mocks/doc.go
  • pkg/util/mocks/gcpclient/client.go
  • pkg/util/mocks/generate.go
  • pkg/util/mocks/projectclaim/customeresourceadapter.go
  • pkg/util/mocks/status-writer.go
✅ Files skipped from review due to trivial changes (6)
  • pkg/util/mocks/doc.go
  • config/config.go
  • docs/testing.md
  • pkg/util/mocks/gcpclient/client.go
  • controllers/projectclaim/projectclaim_controller.go
  • pkg/util/mocks/status-writer.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/gcpclient/client.go
  • pkg/util/mocks/projectclaim/customeresourceadapter.go
  • pkg/util/mocks/condition/conditions.go

Comment on lines +10 to +11
//go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
//go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Find unpinned mockgen go:generate directives:"
rg -nP 'go run go\.uber\.org/mock/mockgen(?!@)' pkg/util/mocks/generate.go pkg/condition/conditions.go

echo
echo "Compare documented/pinned versions:"
rg -n 'go\.uber\.org/mock|mockgen@' go.mod docs/testing.md pkg/util/mocks/generate.go pkg/condition/conditions.go

Repository: openshift/gcp-project-operator

Length of output: 1366


Pin mockgen in go:generate directives to keep mock outputs reproducible.

  • pkg/util/mocks/generate.go and pkg/condition/conditions.go both run go run go.uber.org/mock/mockgen without an @version (there are existing references to @v0.6.0, while go.mod currently uses go.uber.org/mock v0.4.0).
  • Pinning the generator version prevents silent drift in generated mock code.
Proposed change
-//go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
-//go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
-//go:generate go run go.uber.org/mock/mockgen -destination=../util/mocks/$GOPACKAGE/conditions.go -package=$GOPACKAGE -source conditions.go
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination=../util/mocks/$GOPACKAGE/conditions.go -package=$GOPACKAGE -source conditions.go
📝 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
//go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
//go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
🤖 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 `@pkg/util/mocks/generate.go` around lines 10 - 11, The go:generate directives
in pkg/util/mocks/generate.go currently call go.uber.org/mock/mockgen without a
version which allows the generator to drift; update the two directives (the
lines invoking mockgen for Client and StatusWriter) to pin a specific mockgen
module version (e.g., append `@v0.6.0` to go.uber.org/mock/mockgen) and make the
same pinning change wherever else mockgen is invoked (e.g.,
pkg/condition/conditions.go) so generated mocks remain reproducible and
consistent with the repo's intended generator version.

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from e6ccc93 to a21f9c5 Compare June 5, 2026 16:19
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 5, 2026

@sebrandon1: 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/validate a21f9c5 link true /test validate

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

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants