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

@sebrandon1 sebrandon1 commented Nov 13, 2025

Copy link
Copy Markdown
Member

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 internal marker fields and a few mock method signatures were adjusted.

@codecov-commenter

codecov-commenter commented Nov 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.77778% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.62%. Comparing base (8a2f4cc) to head (64b3f8b).

Files with missing lines Patch % Lines
pkg/util/mocks/cr-client.go 30.76% 32 Missing and 4 partials ⚠️
pkg/util/mocks/status-writer.go 20.00% 15 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (27.77%) 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   57.62%   57.62%           
=======================================
  Files          26       26           
  Lines        1966     1966           
=======================================
  Hits         1133     1133           
  Misses        755      755           
  Partials       78       78           
Files with missing lines Coverage Δ
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 29.62% <20.00%> (ø)
pkg/util/mocks/cr-client.go 35.52% <30.76%> (ø)
🚀 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

openshift-ci-robot commented Apr 30, 2026

Copy link
Copy Markdown

@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

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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 | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning Test assertions lack meaningful failure messages (e.g., Expect(err).NotTo(HaveOccurred()) instead of including context). This violates requirement #4 for assertion quality. Add descriptive messages to Expect() calls to help diagnose failures, e.g., Expect(err).NotTo(HaveOccurred(), "failed to reconcile project claim").
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: migrating from the deprecated golang/mock to the maintained uber-go/mock library, which is the core objective of all modifications across the codebase.
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 All Ginkgo test names in the PR are stable and deterministic, using only static descriptive strings with no dynamic pod names, timestamps, UUIDs, node names, or IP addresses.
Microshift Test Compatibility ✅ Passed This PR does not add any new Ginkgo e2e tests. It only migrates mock generation tooling and regenerates existing mocks; the check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR migrates mock generation from golang/mock to uber-go/mock; no new Ginkgo e2e tests are added, making the check inapplicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR is a testing infrastructure maintenance update (mockgen migration). No deployment manifests, scheduling constraints, or topology-aware code changes.
Ote Binary Stdout Contract ✅ Passed PR contains only mockgen dependency migration and mock regeneration. No stdout writes in process-level code or init functions were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests added. All tests are from initial import with no IPv4 hardcoded addresses, IPv4-specific parsing, or external connectivity found.
No-Weak-Crypto ✅ Passed PR is a mocking library migration with no weak cryptography, custom crypto implementations, or unsafe secret comparisons introduced or modified.
Container-Privileges ✅ Passed PR modifies only Go source files and documentation for mockgen migration; no Kubernetes manifests, Dockerfiles, or container configs were changed, so privilege escalation check does not apply.
No-Sensitive-Data-In-Logs ✅ Passed PR contains no new logging statements. All changes are //go:generate directives, formatting, and generated mock file regeneration. No sensitive data exposure in logs.

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

@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

@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: 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 thread pkg/util/mocks/generate.go Outdated
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 2 times, most recently from a21f9c5 to bd47dfe Compare June 10, 2026 18:54

@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: 1

♻️ Duplicate comments (1)
pkg/util/mocks/generate.go (1)

10-11: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pin mockgen version in go:generate directives to ensure reproducible mock generation.

The go:generate directives run go run go.uber.org/mock/mockgen without a version pin, allowing the generator version to drift. This matches the concern previously raised in the past review.

📌 Proposed fix
-//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
invoke go.run for go.uber.org/mock/mockgen without a version, allowing the
generator to drift; update both directives in pkg/util/mocks/generate.go to pin
a specific mockgen module version (e.g., change "go run
go.uber.org/mock/mockgen" to "go run go.uber.org/mock/mockgen@vX.Y.Z") so mock
generation is reproducible, and apply the same version pin to both the Client
and StatusWriter directives.
🤖 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 7-8: The build uses mockgen version mismatch: the generate.go
comment (and docs) say to install go.uber.org/mock/mockgen@v0.6.0 but
go:generate will use the version pinned in go.mod (go.uber.org/mock v0.4.0).
Pick one approach and make them consistent: either update go.mod to require
go.uber.org/mock v0.6.0 so go:generate uses v0.6.0, or change the install
comment in pkg/util/mocks/generate.go (and docs/testing.md) to instruct
installing go.uber.org/mock/mockgen@v0.4.0 to match the existing go.mod; update
the //go:generate directives in generate.go only if you change the go.mod
version. Ensure the chosen version string (v0.6.0 or v0.4.0) is used everywhere.

---

Duplicate comments:
In `@pkg/util/mocks/generate.go`:
- Around line 10-11: The go:generate directives invoke go.run for
go.uber.org/mock/mockgen without a version, allowing the generator to drift;
update both directives in pkg/util/mocks/generate.go to pin a specific mockgen
module version (e.g., change "go run go.uber.org/mock/mockgen" to "go run
go.uber.org/mock/mockgen@vX.Y.Z") so mock generation is reproducible, and apply
the same version pin to both the Client and StatusWriter directives.
🪄 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: 80d73620-9333-4755-aba3-8dbd6b754fd0

📥 Commits

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

⛔ 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 (10)
  • pkg/condition/conditions.go
  • pkg/gcpclient/client.go
  • pkg/util/mocks/doc.go
  • pkg/util/mocks/projectclaim/customeresourceadapter.go
  • pkg/util/mocks/gcpclient/client.go
  • docs/testing.md
  • config/config.go
  • controllers/projectclaim/projectclaim_controller.go
  • pkg/util/mocks/condition/conditions.go
  • pkg/util/mocks/status-writer.go

Comment thread pkg/util/mocks/generate.go Outdated
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch 4 times, most recently from de54a74 to d0897cc Compare June 22, 2026 16:12
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from d0897cc to 457d7ec Compare June 26, 2026 18:03
@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 2, 2026
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from 457d7ec to 10c2877 Compare July 6, 2026 16:20
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 6, 2026
Migrate from the archived github.com/golang/mock to the maintained
fork go.uber.org/mock. Regenerate all mock files with the new mockgen.
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from 10c2877 to 64b3f8b Compare July 8, 2026 20:51
@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

[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

@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@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 64b3f8b 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