Skip to content

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

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

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

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

@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).

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
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 d66c1ca to 8e4a70e Compare March 20, 2026 19:44
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

Walkthrough

This pull request migrates the mock generation framework from github.com/golang/mock/gomock to go.uber.org/mock/gomock across the codebase. The changes include updating the go.mod dependency, replacing import statements in test and generated mock files, and standardizing type parameters from interface{} to any in generated mock files.

Changes

Cohort / File(s) Summary
Dependency Management
go.mod
Removed github.com/golang/mock v1.7.0-rc.1 and added go.uber.org/mock v0.6.0 as direct dependency.
AWS Test Files
pkg/aws/actuator/actuator_test.go, pkg/cmd/provisioning/aws/create-iam-roles_test.go, pkg/cmd/provisioning/aws/create_identity_provider_test.go
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files.
AWS Generated Mocks
pkg/aws/mock/client_generated.go
Updated gomock import; added isgomock struct{} field to MockClient; replaced interface{} with any in all mock recorder method parameters.
Azure Test Files
pkg/azure/actuator_test.go, pkg/cmd/provisioning/azure/create_managed_identities_test.go, pkg/cmd/provisioning/azure/create_oidc_issuer_test.go, pkg/operator/credentialsrequest/credentialsrequest_controller_azure_test.go
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files.
Azure Generated Mocks
pkg/azure/mock/client_generated.go, pkg/operator/secretannotator/azure/mock/adal_generated.go
Updated gomock import; added isgomock struct{} field to all mock types; standardized recorder method parameters from interface{} to any.
GCP Test Files
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/operator/credentialsrequest/credentialsrequest_controller_gcp_test.go, pkg/operator/secretannotator/gcp/reconciler_test.go, pkg/operator/utils/gcp/utils_test.go
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files; minor type adjustments in utils_test.go.
GCP Generated Mocks
pkg/gcp/mock/client_generated.go
Updated gomock import; added isgomock struct{} field to MockClient; replaced interface{} with any in all mock recorder method parameters across 28 methods.
IBM Cloud Test Files
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
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files.
IBM Cloud Generated Mocks
pkg/ibmcloud/mock/client_generated.go
Updated gomock import; added isgomock struct{} field to MockClient; replaced interface{} with any in mock recorder method parameters.
Operator Controller & Webhook Tests
pkg/operator/cleanup/cleanup_controller_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
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files.
Operator Reconciler Tests
pkg/operator/secretannotator/aws/reconciler_test.go, pkg/operator/secretannotator/vsphere/reconciler_test.go
Updated gomock import from github.com/golang/mock to go.uber.org/mock in test files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

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

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

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.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 20, 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/security 8e4a70e link true /test security
ci/prow/e2e-azure-manual-oidc 8e4a70e 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants