Skip to content

OCPBUGS-65687: fix(cpo): prevent informer creation for inaccessible resource types - #7819

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
muraee:fix/cpo-skip-inaccessible-gvk-informers
Mar 14, 2026
Merged

OCPBUGS-65687: fix(cpo): prevent informer creation for inaccessible resource types#7819
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
muraee:fix/cpo-skip-inaccessible-gvk-informers

Conversation

@muraee

@muraee muraee commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Bug: When a CRD like SecretProviderClass is installed on a non-Azure management cluster, the CPOv2 component framework triggers cleanup for components whose predicate returns false (e.g. Azure-only components on an AWS cluster). During cleanup, both the genericAdapter.reconcile() and controlPlaneWorkload.delete() paths call Client.Get() on the cached client to check if the resource exists before deleting it. The cached client creates an informer as a side effect of Get(), and these informers fail permanently with 403 Forbidden when the CPO has no RBAC for the resource type. The informer retries LIST/WATCH forever, blocking reconciliation of the entire hosted control plane.
  • Fix: Introduces a GVKAccessChecker interface (backed by gvkAccessCache) that probes each GVK's accessibility once using an uncached reader (no informer created), caches the result, and either skips (inaccessible) or proceeds with the normal cached client (accessible) for all subsequent reconciles. The probe is inserted before both cleanup paths: the predicate-false branch in genericAdapter.reconcile() and the manifest deletion loop in controlPlaneWorkload.delete().
  • Logs a message when a resource type is first determined to be inaccessible for observability.

Refs: OCPBUGS-65687

Test plan

  • Unit tests for GVKAccessChecker covering all error paths (Forbidden, NoMatch, NotFound, OK, transient errors, cache hit, empty GVK)
  • Unit tests for genericAdapter.reconcile() verifying skip behavior when predicate is false and GVK is inaccessible
  • Existing controlplane-component tests pass
  • Existing CPO controller fixture tests pass
  • Manual verification on a non-Azure cluster with SecretProviderClass CRD installed

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added GVK accessibility checking mechanism that gracefully handles unavailable Kubernetes API resources, automatically skipping operations on inaccessible resources.
    • Improved error handling and logging for resource accessibility scenarios.
  • Tests

    • Comprehensive test coverage for GVK accessibility checking across various scenarios and error conditions.

When a CRD like SecretProviderClass is installed on a non-Azure
management cluster, the CPO creates informers for it during cleanup.
The informer's LIST/WATCH fails with 403 Forbidden (no RBAC), retries
forever, and blocks reconciliation of the entire hosted control plane.

Introduce GVKAccessChecker that probes each GVK's accessibility once
using an uncached reader (no informer created), caches the result, and
either skips (inaccessible) or uses the normal cached client (accessible)
for all subsequent reconciles.

Refs: OCPBUGS-65687
Signed-off-by: Mulham Raee <mulham.raee@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci-robot

Copy link
Copy Markdown

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@muraee muraee changed the title fix(cpo): prevent informer creation for inaccessible resource types OCPBUGS-65687: fix(cpo): prevent informer creation for inaccessible resource types Feb 27, 2026
@openshift-ci-robot openshift-ci-robot added jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. labels Feb 27, 2026
@coderabbitai

coderabbitai Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces a GVK accessibility probing and caching mechanism for control plane components. A new GVKAccessChecker interface determines if a resource's GVK is accessible before reconciliation operations. The checker is integrated into the reconciler, wired through the control plane context, and used in deletion and reconciliation paths to skip inaccessible resources.

Changes

Cohort / File(s) Summary
Reconciler Setup
control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go, control-plane-operator/main.go
Added GVKAccessChecker field to HostedControlPlaneReconciler and initialized it in main via component.NewGVKAccessCache(mgr.GetAPIReader()).
Control Plane Context
support/controlplane-component/controlplane-component.go
Added GVKAccessChecker field to ControlPlaneContext and integrated access check gating in deletion path—skips manifest deletion if GVK is inaccessible.
Generic Adapter Reconciliation
support/controlplane-component/generic-adapter.go
Added early-access control in reconcile method: when predicate is false, probes GVK accessibility via cpContext.GVKAccessChecker.GetOrProbe; skips further processing if inaccessible or propagates probe errors.
GVK Cache Implementation
support/controlplane-component/gvk_cache.go
New GVKAccessChecker interface and NewGVKAccessCache constructor providing caching GVK accessibility checks using sync.Map. Caches based on result type: accessible/forbidden on Forbidden or NoMatch, but not transient errors.
Test Coverage
support/controlplane-component/gvk_cache_test.go
Comprehensive test suite for GVKAccessCache covering caching behavior for Forbidden, NoMatch, NotFound, success, transient errors, and empty GVK scenarios.
Generic Adapter Tests
support/controlplane-component/generic-adapter_test.go
Extensive test suite for generic adapter reconciliation covering predicate/GVK check interactions, accessibility states, error propagation, and deletion with HCP owner references.

Sequence Diagram

sequenceDiagram
    participant Reconciler
    participant GenericAdapter
    participant GVKAccessChecker
    participant Reader
    participant Cache

    Reconciler->>GenericAdapter: reconcile(obj)
    GenericAdapter->>GenericAdapter: evaluate predicate
    alt Predicate is true
        GenericAdapter->>GenericAdapter: proceed with adapt & apply
    else Predicate is false
        GenericAdapter->>GVKAccessChecker: GetOrProbe(ctx, obj)
        GVKAccessChecker->>Cache: lookup GVK
        alt Cache hit
            Cache-->>GVKAccessChecker: cached result
        else Cache miss
            GVKAccessChecker->>Reader: Get(ctx, obj)
            alt Reader returns success/NotFound
                Reader-->>GVKAccessChecker: accessible=true
                GVKAccessChecker->>Cache: store accessible
            else Reader returns Forbidden/NoMatch
                Reader-->>GVKAccessChecker: error
                GVKAccessChecker->>Cache: store inaccessible
            else Reader returns transient error
                Reader-->>GVKAccessChecker: error
                GVKAccessChecker-->>GenericAdapter: propagate error
            end
        end
        GVKAccessChecker-->>GenericAdapter: (accessible, error)
        alt Accessible
            GenericAdapter->>GenericAdapter: check ownership, delete if needed
        else Not accessible
            GenericAdapter->>GenericAdapter: skip processing
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 ⚠️ Warning Test files lack meaningful failure messages in assertions, which is required by code review guidelines and used elsewhere in the codebase. Add descriptive failure messages to all assertions in both test files to provide clear diagnostic information when assertions fail.
✅ Passed checks (3 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: preventing informer creation for inaccessible resource types via a GVK access checker mechanism.
Stable And Deterministic Test Names ✅ Passed All test names in both test files are stable, deterministic, and descriptive with no dynamic information.

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

@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Feb 27, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@muraee: This pull request references Jira Issue OCPBUGS-65687, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.22.0) matches configured target version for branch (4.22.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @xiuwang

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Bug: When a CRD like SecretProviderClass is installed on a non-Azure management cluster, the CPOv2 component framework triggers cleanup for components whose predicate returns false (e.g. Azure-only components on an AWS cluster). During cleanup, both the genericAdapter.reconcile() and controlPlaneWorkload.delete() paths call Client.Get() on the cached client to check if the resource exists before deleting it. The cached client creates an informer as a side effect of Get(), and these informers fail permanently with 403 Forbidden when the CPO has no RBAC for the resource type. The informer retries LIST/WATCH forever, blocking reconciliation of the entire hosted control plane.
  • Fix: Introduces a GVKAccessChecker interface (backed by gvkAccessCache) that probes each GVK's accessibility once using an uncached reader (no informer created), caches the result, and either skips (inaccessible) or proceeds with the normal cached client (accessible) for all subsequent reconciles. The probe is inserted before both cleanup paths: the predicate-false branch in genericAdapter.reconcile() and the manifest deletion loop in controlPlaneWorkload.delete().
  • Logs a message when a resource type is first determined to be inaccessible for observability.

Refs: OCPBUGS-65687

Test plan

  • Unit tests for GVKAccessChecker covering all error paths (Forbidden, NoMatch, NotFound, OK, transient errors, cache hit, empty GVK)
  • Unit tests for genericAdapter.reconcile() verifying skip behavior when predicate is false and GVK is inaccessible
  • Existing controlplane-component tests pass
  • Existing CPO controller fixture tests pass
  • Manual verification on a non-Azure cluster with SecretProviderClass CRD installed

🤖 Generated with Claude Code

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.

@openshift-ci
openshift-ci Bot requested a review from xiuwang February 27, 2026 10:36
@openshift-ci
openshift-ci Bot requested review from devguyio and sjenning February 27, 2026 10:36
@openshift-ci openshift-ci Bot added area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Feb 27, 2026
@openshift-ci

openshift-ci Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: muraee

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 Feb 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
support/controlplane-component/generic-adapter_test.go (1)

118-130: Minor: Unused variable in test.

The variable obj created on line 118 is assigned but never used (line 129 just suppresses the unused warning with _ = obj). Consider removing it since the test only uses cmObj.

♻️ Suggested cleanup
 	t.Run("When predicate is false and GVK checker is nil it should proceed with existing logic", func(t *testing.T) {
 		g := NewWithT(t)
 
 		// No checker — backward compatibility.
 		cpCtx := testCPContext(t, nil)
 
 		ga := &genericAdapter{
 			predicate: func(_ WorkloadContext) bool { return false },
 		}
 
-		obj := testObjWithGVK(inaccessibleGVK)
-		// Without a checker the code falls through to Client.Get which will
+		// Without a checker the code falls through to Client.Get which will
 		// return an error or NotFound depending on the fake client setup.
 		// Since the object doesn't exist and the GVK is registered (ConfigMap used in fake),
 		// we use a ConfigMap to avoid scheme issues.
 		cmObj := &corev1.ConfigMap{
 			ObjectMeta: metav1.ObjectMeta{
 				Name:      "test-resource",
 				Namespace: "test-ns",
 			},
 		}
-		_ = obj // unused in this path
 		err := ga.reconcile(cpCtx, cmObj)
 		// Should succeed (object not found → no deletion needed).
 		g.Expect(err).ToNot(HaveOccurred())
 	})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@support/controlplane-component/generic-adapter_test.go` around lines 118 -
130, Remove the unused local variable to clean up the test: delete the call and
assignment to obj := testObjWithGVK(inaccessibleGVK) and the no-op suppression _
= obj, since the test uses cmObj and calls ga.reconcile(cpCtx, cmObj); ensure no
other references to obj or testObjWithGVK remain in generic-adapter_test.go so
the test compiles cleanly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@support/controlplane-component/generic-adapter_test.go`:
- Around line 118-130: Remove the unused local variable to clean up the test:
delete the call and assignment to obj := testObjWithGVK(inaccessibleGVK) and the
no-op suppression _ = obj, since the test uses cmObj and calls
ga.reconcile(cpCtx, cmObj); ensure no other references to obj or testObjWithGVK
remain in generic-adapter_test.go so the test compiles cleanly.

ℹ️ Review info

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

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between f8ef696 and 952d98b.

📒 Files selected for processing (7)
  • control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go
  • control-plane-operator/main.go
  • support/controlplane-component/controlplane-component.go
  • support/controlplane-component/generic-adapter.go
  • support/controlplane-component/generic-adapter_test.go
  • support/controlplane-component/gvk_cache.go
  • support/controlplane-component/gvk_cache_test.go

@enxebre

enxebre commented Mar 11, 2026

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Mar 11, 2026
@openshift-ci-robot

Copy link
Copy Markdown

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws

@jhjaggars

Copy link
Copy Markdown
Contributor

/retest

@xiuwang

xiuwang commented Mar 13, 2026

Copy link
Copy Markdown

/verified by @xiuwang

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

Copy link
Copy Markdown

@xiuwang: This PR has been marked as verified by @xiuwang.

Details

In response to this:

/verified by @xiuwang

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.

@xiuwang

xiuwang commented Mar 13, 2026

Copy link
Copy Markdown

/retest-required

@openshift-ci-robot

Copy link
Copy Markdown

/retest-required

Remaining retests: 0 against base HEAD 259cead and 2 for PR HEAD 952d98b in total

@openshift-ci-robot

Copy link
Copy Markdown

/retest-required

Remaining retests: 0 against base HEAD 2172048 and 1 for PR HEAD 952d98b in total

@openshift-ci-robot

Copy link
Copy Markdown

/retest-required

Remaining retests: 0 against base HEAD 3de8e22 and 0 for PR HEAD 952d98b in total

@openshift-ci

openshift-ci Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

@muraee: all tests passed!

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-merge-bot
openshift-merge-bot Bot merged commit a85cd0a into openshift:main Mar 14, 2026
23 checks passed
@openshift-ci-robot

Copy link
Copy Markdown

@muraee: An error was encountered searching for bug OCPBUGS-65687 on the Jira server at https://issues.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. No response returned: Get "https://issues.redhat.com/rest/api/2/issue/OCPBUGS-65687": GET https://issues.redhat.com/rest/api/2/issue/OCPBUGS-65687 giving up after 5 attempt(s)

Please contact an administrator to resolve this issue, then request a bug refresh with /jira refresh.

Details

In response to this:

Summary

  • Bug: When a CRD like SecretProviderClass is installed on a non-Azure management cluster, the CPOv2 component framework triggers cleanup for components whose predicate returns false (e.g. Azure-only components on an AWS cluster). During cleanup, both the genericAdapter.reconcile() and controlPlaneWorkload.delete() paths call Client.Get() on the cached client to check if the resource exists before deleting it. The cached client creates an informer as a side effect of Get(), and these informers fail permanently with 403 Forbidden when the CPO has no RBAC for the resource type. The informer retries LIST/WATCH forever, blocking reconciliation of the entire hosted control plane.
  • Fix: Introduces a GVKAccessChecker interface (backed by gvkAccessCache) that probes each GVK's accessibility once using an uncached reader (no informer created), caches the result, and either skips (inaccessible) or proceeds with the normal cached client (accessible) for all subsequent reconciles. The probe is inserted before both cleanup paths: the predicate-false branch in genericAdapter.reconcile() and the manifest deletion loop in controlPlaneWorkload.delete().
  • Logs a message when a resource type is first determined to be inaccessible for observability.

Refs: OCPBUGS-65687

Test plan

  • Unit tests for GVKAccessChecker covering all error paths (Forbidden, NoMatch, NotFound, OK, transient errors, cache hit, empty GVK)
  • Unit tests for genericAdapter.reconcile() verifying skip behavior when predicate is false and GVK is inaccessible
  • Existing controlplane-component tests pass
  • Existing CPO controller fixture tests pass
  • Manual verification on a non-Azure cluster with SecretProviderClass CRD installed

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

  • Added GVK accessibility checking mechanism that gracefully handles unavailable Kubernetes API resources, automatically skipping operations on inaccessible resources.

  • Improved error handling and logging for resource accessibility scenarios.

  • Tests

  • Comprehensive test coverage for GVK accessibility checking across various scenarios and error conditions.

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.

@muraee

muraee commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-4.21

@openshift-cherrypick-robot

Copy link
Copy Markdown

@muraee: new pull request created: #8833

Details

In response to this:

/cherry-pick release-4.21

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.

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. area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. 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.

6 participants