Skip to content

CCO-837: mockgen deprecated: use uber-go/mock instead#943

Open
sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
sebrandon1:mockgen_deprecation
Open

CCO-837: mockgen deprecated: use uber-go/mock instead#943
sebrandon1 wants to merge 1 commit intoopenshift: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
    • Updated the testing framework dependency from golang/mock to uber/mock
    • Regenerated mock files with improved type signatures
    • Updated test imports to reference the new testing library

@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch 2 times, most recently from a5aad22 to 01dd97c Compare March 2, 2026 21:21
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Mar 2, 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 dlom 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

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 64.90385% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.28%. Comparing base (f5fb038) to head (8e4a70e).
⚠️ Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
pkg/aws/mock/client_generated.go 57.77% 57 Missing ⚠️
pkg/azure/mock/client_generated.go 70.00% 9 Missing ⚠️
pkg/gcp/mock/client_generated.go 82.35% 6 Missing ⚠️
pkg/ibmcloud/mock/client_generated.go 88.88% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #943   +/-   ##
=======================================
  Coverage   46.28%   46.28%           
=======================================
  Files          98       98           
  Lines       12259    12259           
=======================================
  Hits         5674     5674           
  Misses       5935     5935           
  Partials      650      650           
Files with missing lines Coverage Δ
...rator/secretannotator/azure/mock/adal_generated.go 0.00% <ø> (ø)
pkg/ibmcloud/mock/client_generated.go 82.35% <88.88%> (ø)
pkg/gcp/mock/client_generated.go 83.85% <82.35%> (ø)
pkg/azure/mock/client_generated.go 70.08% <70.00%> (ø)
pkg/aws/mock/client_generated.go 49.74% <57.77%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from 01dd97c to d66c1ca Compare March 2, 2026 21:35
@sebrandon1
Copy link
Copy Markdown
Member Author

/retest-required

@jstuever
Copy link
Copy Markdown
Contributor

jstuever commented Mar 5, 2026

/cc

@openshift-ci openshift-ci Bot requested a review from jstuever March 5, 2026 19:48
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from d66c1ca to 8e4a70e Compare March 20, 2026 19:44
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8f1162c0-297b-4b53-b8cd-7f36f7467931

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4a70e and 2fd9850.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • vendor/github.com/golang/mock/CONTRIBUTORS is excluded by !**/vendor/**, !vendor/**
📒 Files selected for processing (29)
  • go.mod
  • pkg/aws/actuator/actuator_test.go
  • pkg/aws/mock/client_generated.go
  • pkg/azure/actuator_test.go
  • pkg/azure/mock/client_generated.go
  • pkg/cmd/provisioning/aws/create-iam-roles_test.go
  • pkg/cmd/provisioning/aws/create_identity_provider_test.go
  • pkg/cmd/provisioning/azure/create_managed_identities_test.go
  • pkg/cmd/provisioning/azure/create_oidc_issuer_test.go
  • pkg/cmd/provisioning/gcp/create_service_accounts_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_pool_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_provider_test.go
  • pkg/cmd/provisioning/ibmcloud/create_service_id_test.go
  • pkg/cmd/provisioning/ibmcloud/delete_service_id_test.go
  • pkg/cmd/provisioning/ibmcloud/refresh-keys_test.go
  • pkg/gcp/mock/client_generated.go
  • pkg/ibmcloud/mock/client_generated.go
  • pkg/operator/cleanup/cleanup_controller_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_azure_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_gcp_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_vsphere_test.go
  • pkg/operator/credentialsrequest/status_test.go
  • pkg/operator/podidentity/podidentitywebhook_controller_test.go
  • pkg/operator/secretannotator/aws/reconciler_test.go
  • pkg/operator/secretannotator/azure/mock/adal_generated.go
  • pkg/operator/secretannotator/gcp/reconciler_test.go
  • pkg/operator/secretannotator/vsphere/reconciler_test.go
  • pkg/operator/utils/gcp/utils_test.go
✅ Files skipped from review due to trivial changes (20)
  • pkg/operator/secretannotator/aws/reconciler_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_pool_test.go
  • pkg/operator/cleanup/cleanup_controller_test.go
  • pkg/operator/credentialsrequest/status_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_vsphere_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_azure_test.go
  • pkg/cmd/provisioning/ibmcloud/delete_service_id_test.go
  • pkg/operator/secretannotator/vsphere/reconciler_test.go
  • pkg/cmd/provisioning/ibmcloud/refresh-keys_test.go
  • pkg/operator/podidentity/podidentitywebhook_controller_test.go
  • pkg/aws/actuator/actuator_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_test.go
  • pkg/azure/actuator_test.go
  • pkg/operator/secretannotator/azure/mock/adal_generated.go
  • pkg/cmd/provisioning/aws/create_identity_provider_test.go
  • pkg/cmd/provisioning/gcp/create_service_accounts_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_provider_test.go
  • pkg/cmd/provisioning/aws/create-iam-roles_test.go
  • pkg/ibmcloud/mock/client_generated.go
  • pkg/cmd/provisioning/azure/create_managed_identities_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/cmd/provisioning/ibmcloud/create_service_id_test.go
  • go.mod
  • pkg/cmd/provisioning/azure/create_oidc_issuer_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_gcp_test.go
  • pkg/azure/mock/client_generated.go
  • pkg/gcp/mock/client_generated.go

Walkthrough

The PR migrates Go mock usage from github.com/golang/mock/gomock to go.uber.org/mock/gomock, updates go.mod, replaces imports in tests and generated mocks, adds isgomock struct{} marker fields to generated mock types, and standardizes recorder parameter types from interface{} to any in generated files; generation headers were also added.

Changes

Cohort / File(s) Summary
Dependency Management
go.mod
Removed github.com/golang/mock requirement and added go.uber.org/mock v0.6.0 as a direct dependency.
Generated mocks (AWS, Azure, GCP, IBM Cloud, others)
pkg/aws/mock/client_generated.go, pkg/azure/mock/client_generated.go, pkg/gcp/mock/client_generated.go, pkg/ibmcloud/mock/client_generated.go, pkg/operator/secretannotator/azure/mock/adal_generated.go, ...
Updated gomock import to go.uber.org/mock/gomock; added isgomock struct{} field to exported mock structs; changed recorder parameter types from interface{} to any/...any/[]any; added mockgen command header comments.
Test files (many providers & controllers)
pkg/aws/..._test.go, pkg/azure/..._test.go, pkg/gcp/..._test.go, pkg/ibmcloud/..._test.go, pkg/operator/..._test.go, pkg/cmd/provisioning/..._test.go, ...
Replaced test imports from github.com/golang/mock/gomockgo.uber.org/mock/gomock across numerous unit tests; most usages (e.g., gomock.NewController, gomock.Any) are unchanged aside from resolving to the new package.
Small test adjustments
pkg/operator/utils/gcp/utils_test.go
Replaced a local accumulator type from []*gomock.Call to []any to match recorder/expectation changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ❓ Inconclusive Custom check is designed for Ginkgo test assessment, but PR modifies standard Go testing.T tests using table-driven patterns, with only 5 Ginkgo files in repository (none modified). Clarify whether test quality assessment applies to standard Go tests; if so, adapt criteria for table-driven test evaluation.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: migrating from the deprecated github.com/golang/mock to go.uber.org/mock, which is the primary objective across all files in this pull request.
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 migrates mock library without introducing Ginkgo tests with dynamic names. Standard Go testing framework used throughout.
Microshift Test Compatibility ✅ Passed This PR only updates mock library dependencies from golang/mock to go.uber.org/mock without adding any new Ginkgo e2e tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This pull request does not add any new Ginkgo e2e tests. All changes are mock library migration updates to existing test files.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only test files, mock files, and go.mod dependency. No changes to deployment manifests, operator controllers, or production scheduling code.
Ote Binary Stdout Contract ✅ Passed Pull request updates GoMock dependency from archived github.com/golang/mock to maintained go.uber.org/mock with no production code or process-level modifications.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR migrates mock library dependency; all test files are Go unit tests, not Ginkgo e2e tests. No new tests added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Review rate limit: 0/10 reviews remaining, refill in 57 minutes and 38 seconds.

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

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)
pkg/gcp/mock/client_generated.go (1)

3-7: Pin the mock generator invocation to avoid regen drift.

All go:generate directives in this codebase use a bare mockgen binary, which can resolve to either archived golang/mock or go.uber.org/mock depending on local PATH. Pin generation to go.uber.org/mock/mockgen (ideally with an explicit version) across all generation directives:

  • pkg/ibmcloud/client.go
  • pkg/gcp/client.go
  • pkg/aws/client.go
  • pkg/azure/clients.go

Note: The codebase has already migrated to go.uber.org/mock/gomock imports, so no legacy import cleanup is needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/gcp/mock/client_generated.go` around lines 3 - 7, The generate directive
currently calls the unqualified "mockgen" which can resolve to different
binaries; update the go:generate lines that invoke mockgen (the lines mirroring
the header in client_generated.go) to call the module-qualified binary
"go.uber.org/mock/mockgen" instead of the bare "mockgen" (so the generated mock
uses the uber/mock implementation consistently); apply the same change to the
client go:generate directives for the other cloud client files that generate
mocks (the client generation directives for GCP/AWS/Azure/IBM client mocks) so
generation is pinned to the go.uber.org/mock/mockgen implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go.mod`:
- Line 51: Add a pinned mockgen generator and update the //go:generate
invocations to call that pinned version: create a tools.go (e.g., package tools)
with a blank import for the generator module (go.uber.org/mock v0.6.0) to record
the tool in go.mod, then change the generate comments in pkg/aws/client.go,
pkg/gcp/client.go, pkg/ibmcloud/client.go, and pkg/azure/clients.go to invoke
the pinned generator explicitly (for example: use "go run
go.uber.org/mock/mockgen@v0.6.0 ..." in the //go:generate lines) so mock
regeneration is reproducible and tied to the go.mod entry you added.

---

Nitpick comments:
In `@pkg/gcp/mock/client_generated.go`:
- Around line 3-7: The generate directive currently calls the unqualified
"mockgen" which can resolve to different binaries; update the go:generate lines
that invoke mockgen (the lines mirroring the header in client_generated.go) to
call the module-qualified binary "go.uber.org/mock/mockgen" instead of the bare
"mockgen" (so the generated mock uses the uber/mock implementation
consistently); apply the same change to the client go:generate directives for
the other cloud client files that generate mocks (the client generation
directives for GCP/AWS/Azure/IBM client mocks) so generation is pinned to the
go.uber.org/mock/mockgen implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 056cff1a-a3d6-404f-a8de-1ab99a0c4a69

📥 Commits

Reviewing files that changed from the base of the PR and between f5fb038 and 8e4a70e.

⛔ Files ignored due to path filters (11)
  • go.sum is excluded by !**/*.sum
  • vendor/github.com/golang/mock/CONTRIBUTORS is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/AUTHORS is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/LICENSE is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/call.go is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/callset.go is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/controller.go is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/doc.go is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/matchers.go is excluded by !vendor/**, !**/vendor/**
  • vendor/go.uber.org/mock/gomock/string.go is excluded by !vendor/**, !**/vendor/**
  • vendor/modules.txt is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (29)
  • go.mod
  • pkg/aws/actuator/actuator_test.go
  • pkg/aws/mock/client_generated.go
  • pkg/azure/actuator_test.go
  • pkg/azure/mock/client_generated.go
  • pkg/cmd/provisioning/aws/create-iam-roles_test.go
  • pkg/cmd/provisioning/aws/create_identity_provider_test.go
  • pkg/cmd/provisioning/azure/create_managed_identities_test.go
  • pkg/cmd/provisioning/azure/create_oidc_issuer_test.go
  • pkg/cmd/provisioning/gcp/create_service_accounts_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_pool_test.go
  • pkg/cmd/provisioning/gcp/create_workload_identity_provider_test.go
  • pkg/cmd/provisioning/ibmcloud/create_service_id_test.go
  • pkg/cmd/provisioning/ibmcloud/delete_service_id_test.go
  • pkg/cmd/provisioning/ibmcloud/refresh-keys_test.go
  • pkg/gcp/mock/client_generated.go
  • pkg/ibmcloud/mock/client_generated.go
  • pkg/operator/cleanup/cleanup_controller_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_azure_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_gcp_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_test.go
  • pkg/operator/credentialsrequest/credentialsrequest_controller_vsphere_test.go
  • pkg/operator/credentialsrequest/status_test.go
  • pkg/operator/podidentity/podidentitywebhook_controller_test.go
  • pkg/operator/secretannotator/aws/reconciler_test.go
  • pkg/operator/secretannotator/azure/mock/adal_generated.go
  • pkg/operator/secretannotator/gcp/reconciler_test.go
  • pkg/operator/secretannotator/vsphere/reconciler_test.go
  • pkg/operator/utils/gcp/utils_test.go

Comment thread go.mod
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
github.com/tidwall/gjson v1.18.0
go.uber.org/mock v0.6.0
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '== stale golang/mock references ==\n'
rg -n -C1 --glob '!vendor/**' 'github\.com/golang/mock' . || true

printf '\n== mock generation / tool pinning ==\n'
rg -n -C2 --glob '!vendor/**' 'go\.uber\.org/mock/mockgen|//go:generate .*mockgen|go install .*mockgen|go run .*mockgen|_ "go\.uber\.org/mock/mockgen"|^\s*tool\s+go\.uber\.org/mock/mockgen\b' . || true

Repository: openshift/cloud-credential-operator

Length of output: 2431


Pin the mockgen generator tool to ensure reproducible mock regeneration.

Line 51 adds the runtime dependency go.uber.org/mock v0.6.0, but the //go:generate mockgen invocations in pkg/aws/client.go, pkg/gcp/client.go, pkg/ibmcloud/client.go, and pkg/azure/clients.go remain unpinned. Without a pinned generator, future regenerations risk inconsistency or drift. Define and use a pinned mockgen entry (e.g., via tools.go, go install, or a tool wrapper) to guarantee reproducibility across environments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go.mod` at line 51, Add a pinned mockgen generator and update the
//go:generate invocations to call that pinned version: create a tools.go (e.g.,
package tools) with a blank import for the generator module (go.uber.org/mock
v0.6.0) to record the tool in go.mod, then change the generate comments in
pkg/aws/client.go, pkg/gcp/client.go, pkg/ibmcloud/client.go, and
pkg/azure/clients.go to invoke the pinned generator explicitly (for example: use
"go run go.uber.org/mock/mockgen@v0.6.0 ..." in the //go:generate lines) so mock
regeneration is reproducible and tied to the go.mod entry you added.

@jstuever
Copy link
Copy Markdown
Contributor

jstuever commented Apr 6, 2026

I am waiting until after branching to review/merge this.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 6, 2026
@jstuever jstuever changed the title mockgen deprecated: use uber-go/mock instead CCO-837: mockgen deprecated: use uber-go/mock instead Apr 23, 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 23, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 23, 2026

@sebrandon1: This pull request references CCO-837 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.

Migrate from the archived github.com/golang/mock to the actively
maintained go.uber.org/mock. Updates all imports, regenerates mocks,
and fixes the InOrder API change in utils_test.go.
@sebrandon1 sebrandon1 force-pushed the mockgen_deprecation branch from 8e4a70e to 2fd9850 Compare April 30, 2026 19:04
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 30, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

@sebrandon1: 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/e2e-aws-ovn 2fd9850 link true /test e2e-aws-ovn
ci/prow/e2e-hypershift 2fd9850 link true /test e2e-hypershift
ci/prow/security 2fd9850 link true /test security
ci/prow/unit 2fd9850 link true /test unit
ci/prow/verify 2fd9850 link true /test verify
ci/prow/verify-deps 2fd9850 link true /test verify-deps
ci/prow/coverage 2fd9850 link true /test coverage
ci/prow/okd-scos-images 2fd9850 link true /test okd-scos-images
ci/prow/images 2fd9850 link true /test images
ci/prow/e2e-upgrade 2fd9850 link true /test e2e-upgrade
ci/prow/e2e-aws-cco-parallel 2fd9850 link false /test e2e-aws-cco-parallel
ci/prow/e2e-azure-manual-oidc 2fd9850 link true /test e2e-azure-manual-oidc

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