Skip to content

CNTRLPLANE-2777: refactor(lib/resourcebuilder): generate interface for client instead of their specific types#1344

Open
ingvagabund wants to merge 1 commit intoopenshift:mainfrom
ingvagabund:lib-resourcebuilder-interfaces
Open

CNTRLPLANE-2777: refactor(lib/resourcebuilder): generate interface for client instead of their specific types#1344
ingvagabund wants to merge 1 commit intoopenshift:mainfrom
ingvagabund:lib-resourcebuilder-interfaces

Conversation

@ingvagabund
Copy link
Member

@ingvagabund ingvagabund commented Mar 10, 2026

Required for building unit tests injecting fake clients

Summary by CodeRabbit

  • Refactor
    • Updated public client type names from "Client" to "Interface" suffix across Kubernetes, OpenShift, and operator framework API clients for improved API consistency.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

This change replaces concrete Kubernetes and OpenShift client types with their corresponding interface equivalents across the resource builder infrastructure. The generation script updates type annotations from pointer references to direct type references, and 11 client field types are updated from Client suffix to Interface suffix.

Changes

Cohort / File(s) Summary
Type Signature Updates
hack/generate-lib-resources.py, lib/resourcebuilder/resourcebuilder.go
Updated 11 client type mappings from concrete Client types to Interface types (e.g., CoreV1ClientCoreV1Interface). Generation script removes pointer-like prefix from type annotations; resource builder struct fields reflect corresponding interface types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Stable And Deterministic Test Names ✅ Passed This PR does not modify any Ginkgo test names. Changes are limited to a Python code generation script and a generated Go source file. The existing test file uses Go's standard testing framework, not Ginkgo, and remains unchanged.
Test Structure And Quality ✅ Passed PR contains no Ginkgo test code; custom check for Ginkgo test quality is not applicable.
Title check ✅ Passed The title accurately describes the main change: refactoring lib/resourcebuilder to use interfaces instead of concrete client types, which aligns with the objectives and file modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

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

🧹 Nitpick comments (2)
lib/resourcebuilder/resourcebuilder.go (1)

45-45: Unused client fields detected.

apiregistrationClientv1 (line 45) and configClientv1 (line 48) are declared and initialized but never used in the Do() method. This is a pre-existing issue from the generator configuration (noted in the generator review). Since this file is auto-generated, the fix should be applied in hack/generate-lib-resources.py by removing the corresponding entries from the clients dictionary.

Also applies to: 48-48

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

In `@lib/resourcebuilder/resourcebuilder.go` at line 45, Remove the unused client
entries from the generator so they are not emitted: update
hack/generate-lib-resources.py to delete the apiregistrationClientv1 and
configClientv1 keys from the clients dictionary so the generator stops
declaring/initializing the apiregistrationClientv1 and configClientv1 fields in
resourcebuilder.go (they are never referenced in the Do() method); regenerate
the file afterward to ensure the unused fields are gone.
hack/generate-lib-resources.py (1)

294-304: Interface type names are correct.

All interface names match the conventions in k8s client-go and OpenShift client-go packages.

Note: config/v1 (line 295) and apiregistration/v1 (line 304) are defined in clients but have no corresponding entries in types. This results in unused client fields (configClientv1, apiregistrationClientv1) in the generated builder struct. Consider removing these entries if they are not needed, or adding corresponding type entries if they should be supported.

,

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

In `@hack/generate-lib-resources.py` around lines 294 - 304, The clients map
includes entries for 'github.com/openshift/api/config/v1' and
'k8s.io/kube-aggregator/pkg/apis/apiregistration/v1' but there are no matching
entries in the types map, resulting in unused generated builder fields
configClientv1 and apiregistrationClientv1; either remove those two client
entries from the clients mapping or add corresponding type entries in the types
mapping so the generator produces matching types (adjust the clients dict
entries shown and/or the types dict to keep clients and types in sync and
eliminate the unused builder struct fields).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@hack/generate-lib-resources.py`:
- Around line 294-304: The clients map includes entries for
'github.com/openshift/api/config/v1' and
'k8s.io/kube-aggregator/pkg/apis/apiregistration/v1' but there are no matching
entries in the types map, resulting in unused generated builder fields
configClientv1 and apiregistrationClientv1; either remove those two client
entries from the clients mapping or add corresponding type entries in the types
mapping so the generator produces matching types (adjust the clients dict
entries shown and/or the types dict to keep clients and types in sync and
eliminate the unused builder struct fields).

In `@lib/resourcebuilder/resourcebuilder.go`:
- Line 45: Remove the unused client entries from the generator so they are not
emitted: update hack/generate-lib-resources.py to delete the
apiregistrationClientv1 and configClientv1 keys from the clients dictionary so
the generator stops declaring/initializing the apiregistrationClientv1 and
configClientv1 fields in resourcebuilder.go (they are never referenced in the
Do() method); regenerate the file afterward to ensure the unused fields are
gone.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: 8712a449-197b-4489-927d-fe88686e7f41

📥 Commits

Reviewing files that changed from the base of the PR and between c4fb92f and b04ea98.

📒 Files selected for processing (3)
  • hack/generate-lib-resources.py
  • lib/resourcebuilder/resourcebuilder.go
  • lib/resourceread/resourceread.go

…of their specific types

Required for building unit tests injecting fake clients
@ingvagabund ingvagabund force-pushed the lib-resourcebuilder-interfaces branch from b04ea98 to a8de48a Compare March 10, 2026 09:33
@ingvagabund ingvagabund changed the title wip: refactor(lib/resourcebuilder): generate interface for client instead of their specific types refactor(lib/resourcebuilder): generate interface for client instead of their specific types Mar 10, 2026
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2026
Copy link

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

🧹 Nitpick comments (1)
hack/generate-lib-resources.py (1)

294-304: Keep clients aligned with types to avoid dead generated members.

github.com/openshift/api/config/v1 and k8s.io/kube-aggregator/pkg/apis/apiregistration/v1 are still listed here, but they are not present in types. The generator therefore still emits and constructs unused configClientv1 and apiregistrationClientv1 fields in lib/resourcebuilder/resourcebuilder.go. Either prune those entries or filter client_properties to packages declared in types.

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

In `@hack/generate-lib-resources.py` around lines 294 - 304, The clients mapping
in generate-lib-resources.py contains entries for
'github.com/openshift/api/config/v1' and
'k8s.io/kube-aggregator/pkg/apis/apiregistration/v1' that are not present in the
types list, causing unused fields (configClientv1, apiregistrationClientv1) to
be generated in lib/resourcebuilder/resourcebuilder.go; fix by either removing
those two keys from the clients mapping or, better, filter the client_properties
generation to only include packages present in the types collection (i.e., check
the package key exists in the types dict before emitting client entries) so
generated client fields align with types and eliminate dead members.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@hack/generate-lib-resources.py`:
- Around line 294-304: The clients mapping in generate-lib-resources.py contains
entries for 'github.com/openshift/api/config/v1' and
'k8s.io/kube-aggregator/pkg/apis/apiregistration/v1' that are not present in the
types list, causing unused fields (configClientv1, apiregistrationClientv1) to
be generated in lib/resourcebuilder/resourcebuilder.go; fix by either removing
those two keys from the clients mapping or, better, filter the client_properties
generation to only include packages present in the types collection (i.e., check
the package key exists in the types dict before emitting client entries) so
generated client fields align with types and eliminate dead members.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: f5e4ad65-5f6f-4204-bd6c-f33a829da858

📥 Commits

Reviewing files that changed from the base of the PR and between b04ea98 and a8de48a.

📒 Files selected for processing (2)
  • hack/generate-lib-resources.py
  • lib/resourcebuilder/resourcebuilder.go

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 10, 2026

@ingvagabund: 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-agnostic-ovn-upgrade-into-change a8de48a link true /test e2e-agnostic-ovn-upgrade-into-change
ci/prow/e2e-hypershift a8de48a link true /test e2e-hypershift

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.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 11, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 11, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DavidHurta, ingvagabund

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 11, 2026
@ingvagabund ingvagabund changed the title refactor(lib/resourcebuilder): generate interface for client instead of their specific types CNTRLPLANE-2777: refactor(lib/resourcebuilder): generate interface for client instead of their specific types Mar 11, 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 Mar 11, 2026
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Mar 11, 2026

@ingvagabund: This pull request references CNTRLPLANE-2777 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 epic to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Required for building unit tests injecting fake clients

Summary by CodeRabbit

  • Refactor
  • Updated public client type names from "Client" to "Interface" suffix across Kubernetes, OpenShift, and operator framework API clients for improved API consistency.

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.

@ingvagabund
Copy link
Member Author

/verified by CI

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Mar 11, 2026
@openshift-ci-robot
Copy link
Contributor

@ingvagabund: This PR has been marked as verified by CI.

Details

In response to this:

/verified by CI

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.

@ingvagabund
Copy link
Member Author

/retest-required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants