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.
  • Documentation

    • Updated testing docs and mockgen install instructions to reference the new mockgen coordinates and install 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 (76f274a) to head (e6ccc93).

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

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


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Ote Binary Stdout Contract ❌ Error PR introduces fips.go with fmt.Println() in init() at package main level, writing to stdout during process initialization, violating OTE's JSON-only stdout contract. Replace fmt.Println() with fmt.Fprintf(os.Stderr, ...) or configure logging to stderr before this init executes.
✅ 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 clearly and specifically describes the main change: migrating from the deprecated golang/mock library to the maintained uber-go/mock alternative.
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 PR only modifies non-test files (mocks, config, docs, go.mod). No test files (*_test.go) were changed, so no Ginkgo test names were introduced or modified to validate.
Test Structure And Quality ✅ Passed This PR focuses on migrating from golang/mock to go.uber.org/mock and does not modify any test files or add new Ginkgo test code. The check is not applicable.
Microshift Test Compatibility ✅ Passed PR contains no new Ginkgo e2e tests. The check is inapplicable; PR only updates mockgen dependency and generated mock files.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added in this PR. The PR only updates the mockgen dependency from golang/mock to go.uber.org/mock with corresponding configuration and mock file regeneration.
Topology-Aware Scheduling Compatibility ✅ Passed This PR only updates the mock generation tool from golang/mock to go.uber.org/mock. No deployment manifests, operator code with scheduling constraints, or topology changes are introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests are added in this PR. The changes only update mockgen tooling/dependencies and generated mock code, so the IPv6/disconnected network compatibility check does not apply.
No-Weak-Crypto ✅ Passed PR introduces no weak crypto patterns. Changes are exclusively about mock generation framework migration; no crypto algorithms or secret comparisons added.
Container-Privileges ✅ Passed Check not applicable: PR modifies only Go source files, documentation, and go.mod—no Kubernetes manifests or container configs present.
No-Sensitive-Data-In-Logs ✅ Passed PR updates mock generation tool without adding logging statements. No sensitive data (passwords, tokens, API keys, PII, session IDs, hostnames, customer data) is exposed in logs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 from 3cee832 to 23c2388 Compare May 29, 2026 15:08
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch 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

@openshift-ci
Copy link
Copy Markdown
Contributor

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

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.

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