Skip to content

OCPBUGS-39539: clear rogue controller ownerReferences during merge - #1445

Open
savio87 wants to merge 1 commit into
openshift:mainfrom
savio87:OCPBUGS-39539
Open

OCPBUGS-39539: clear rogue controller ownerReferences during merge#1445
savio87 wants to merge 1 commit into
openshift:mainfrom
savio87:OCPBUGS-39539

Conversation

@savio87

@savio87 savio87 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes OCPBUGS-39539: CVO wedges with Failing=True when reconciling a CRD that has a rogue ownerReference with controller: true set by another operator (e.g. OLM).

The Kubernetes API rejects updates when two ownerReferences both claim controller: true. The mergeOwnerRefs function was additive-only — it never cleared conflicting controller flags on existing refs, so the rogue ref persisted alongside CVO's own controller ref, causing the update to fail indefinitely.

This fix adds a post-merge pass: when a required ownerReference has Controller=true, any existing ownerReference (not in the required set) that also has Controller=true gets its Controller field cleared. The rogue reference itself is preserved — only its controller claim is demoted.

Test plan

  • Added unit test: rogue Controller=true ref is cleared when CVO's required ref claims controller
  • Added unit test: existing refs without Controller are left untouched
  • All existing TestMergeOwnerRefs tests pass

Summary by CodeRabbit

  • Bug Fixes
    • Prevented resources from retaining multiple controller references during metadata merging.
    • Existing controller references are cleared when a new required controller reference is added.
    • Non-controller owner references remain unchanged.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

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

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 13, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@savio87: This pull request references Jira Issue OCPBUGS-39539, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

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

Details

In response to this:

Summary

Fixes OCPBUGS-39539: CVO wedges with Failing=True when reconciling a CRD that has a rogue ownerReference with controller: true set by another operator (e.g. OLM).

The Kubernetes API rejects updates when two ownerReferences both claim controller: true. The mergeOwnerRefs function was additive-only — it never cleared conflicting controller flags on existing refs, so the rogue ref persisted alongside CVO's own controller ref, causing the update to fail indefinitely.

This fix adds a post-merge pass: when a required ownerReference has Controller=true, any existing ownerReference (not in the required set) that also has Controller=true gets its Controller field cleared. The rogue reference itself is preserved — only its controller claim is demoted.

Test plan

  • Added unit test: rogue Controller=true ref is cleared when CVO's required ref claims controller
  • Added unit test: existing refs without Controller are left untouched
  • All existing TestMergeOwnerRefs tests pass

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.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e23ab4f-011e-4a96-a67c-188d4ae851fa

📥 Commits

Reviewing files that changed from the base of the PR and between f94dc81 and 5db859d.

📒 Files selected for processing (2)
  • lib/resourcemerge/meta.go
  • lib/resourcemerge/meta_test.go

Walkthrough

The owner-reference merge now clears conflicting existing controller flags when a required controller reference is added. Tests cover both conflicting controller references and preserved non-controller references.

Changes

Owner reference reconciliation

Layer / File(s) Summary
Controller flag reconciliation
lib/resourcemerge/meta.go, lib/resourcemerge/meta_test.go
The merge clears Controller=true from existing references with different UIDs when a required controller reference is present. Tests verify that both references remain and that existing non-controller references are preserved.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 5db85

The change is localized to owner-reference merging and adds focused unit coverage; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the bug and the main change: clearing rogue controller owner references during merge.
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 The changed test uses only t.Run("test#%d", idx); idx comes from a fixed table order. No Ginkgo titles or runtime values, such as names, dates, UUIDs, or IPs, were added.
Test Structure And Quality ✅ Passed The changed test is a standard Go table-driven unit test, not Ginkgo. It creates no resources or waits, uses diagnostic t.Fatalf messages, and matches package conventions.
Microshift Test Compatibility ✅ Passed The PR adds only a standard Go TestMergeOwnerRefs unit test using testing.T; it adds no Ginkgo e2e tests or MicroShift-incompatible API usage.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds a standard Go table-driven unit test, not a new Ginkgo e2e test; no SNO multi-node compatibility check applies.
Topology-Aware Scheduling Compatibility ✅ Passed The diff changes only owner-reference merge logic and unit tests; it adds no manifests, controllers, replicas, affinity, topology spread, selectors, tolerations, or PDB constraints.
Ote Binary Stdout Contract ✅ Passed The diff only changes owner-reference logic and unit-test cases; no added stdout, logging, main, init, or suite-setup writes exist.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added coverage is a standard Go table-driven unit test, not a Ginkgo e2e test, and it adds no IPv4 assumptions or external network access.
No-Weak-Crypto ✅ Passed The PR changes only Kubernetes owner-reference merging and tests; the added code has no MD5, SHA1, DES, RC4, Blowfish, ECB, custom crypto, or secret comparison.
Container-Privileges ✅ Passed The pull request changes only Go source and tests; it adds no container or Kubernetes manifest privilege settings.
No-Sensitive-Data-In-Logs ✅ Passed The diff adds owner-reference logic and synthetic test data only; it introduces no runtime logging or sensitive values in logs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 13, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@savio87: This pull request references Jira Issue OCPBUGS-39539, which is valid. The bug has been moved to the POST state.

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

No GitHub users were found matching the public email listed for the QA contact in Jira (jiajliu@redhat.com), skipping review request.

Details

In response to this:

Summary

Fixes OCPBUGS-39539: CVO wedges with Failing=True when reconciling a CRD that has a rogue ownerReference with controller: true set by another operator (e.g. OLM).

The Kubernetes API rejects updates when two ownerReferences both claim controller: true. The mergeOwnerRefs function was additive-only — it never cleared conflicting controller flags on existing refs, so the rogue ref persisted alongside CVO's own controller ref, causing the update to fail indefinitely.

This fix adds a post-merge pass: when a required ownerReference has Controller=true, any existing ownerReference (not in the required set) that also has Controller=true gets its Controller field cleared. The rogue reference itself is preserved — only its controller claim is demoted.

Test plan

  • Added unit test: rogue Controller=true ref is cleared when CVO's required ref claims controller
  • Added unit test: existing refs without Controller are left untouched
  • All existing TestMergeOwnerRefs tests pass

Summary by CodeRabbit

  • Bug Fixes
  • Prevented resources from retaining multiple controller references during metadata merging.
  • Existing controller references are cleared when a new required controller reference is added.
  • Non-controller owner references remain unchanged.

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 added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 13, 2026
@openshift-ci

openshift-ci Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Hi @savio87. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@openshift-ci

openshift-ci Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: savio87
Once this PR has been reviewed and has the lgtm label, please assign pratikmahajan 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

@savio87

savio87 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

This clears rogue controller ownerReferences that cause CVO to wedge with "only one reference can have Controller set to true" during reconciliation. The rogue ref is preserved — only its controller claim is demoted. Could a maintainer check and run /ok-to-test? Thanks!

@savio87

savio87 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping @PratikMahajan @hongkailiu , CodeRabbit had no actionable comments. This fixes a bug where CVO wedges on CRDs with rogue controller ownerReferences. Would appreciate /ok-to-test when you get a chance. Thanks!

Comment thread lib/resourcemerge/meta.go

// If a required ref claims Controller=true, clear Controller on any
// existing refs not in the required set to avoid the API server
// rejecting the update with "only one reference can have Controller

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Expanding on my 2024 context, this function is old, dating all the way back to 2018, #7, d9f6718. That commit message doesn't go into detail about why the CVO chose to merge itself into ownerReferences instead of compeltely owning ownerReferences in any resource it managed. But it means that now we're in the sticky position of wondering if we can own more of ownerReferences or not. Why does the old controller: true entry exist? Is it safe to clear controller on those entries? Maybe... something.. should be removing those entries? It's hard to know.

For the bug's original clusterserviceversions.operators.coreos.com with Found "true" in references for ClusterServiceVersion/rhsso-operator.7.6.9-opr-002 and ClusterVersion/version, the issue seems to be the RHSSO operator, right? Should it own that CRD? I'd expect the answer is "no, it does not belong in that CRD's ownerReferences at all, and there should be a bug against the RHSSO operator to get it to remove that entry from the CRD's ownerReferences".

Or maybe we want to tighten the CVO's original weak stance up, and say "look, we're a powerful operator, and if we think that resource is ours, we're erasing your attempt at being in ownerReferences entirely". In that case, #7's original weaker stance was an error.

But keeping ownerRerferences entries we don't understand and just clearing controller on them seems like it's sitting in the middle, and that feels messy to me, and I don't see an upside to sitting on the fence. Both "we own ownerReferences on our resources entirely" and "we complain when there's a conflict, so the cluster-admin can dig in and report a bug against whoever falsely thought they were the controller" make sense to me.

@DavidHurta DavidHurta Aug 19, 2026

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.

From the ControllerRef proposal:

The main goal of ControllerRef (controller reference) is to solve the problem of controllers that fight over controlled objects due to overlapping selectors (e.g. a ReplicaSet fighting with a ReplicationController over Pods because both controllers have label selectors that match those Pods). Fighting controllers can destabilize the apiserver, thrash objects back-and-forth, or cause controller operations to hang.

If I understand correctly, in the mentioned bug, the CVO de facto respects the API: once another operator is set as controller, the CVO stops managing the resource. It's de facto because the CVO doesn't check the controllerRef and backs off deliberately - it re-adds its own Controller: true ownerReference on reconcile, the API rejects the update ("only one reference can have Controller set to true"), and the CVO simply can't proceed. It never stomps the rogue ownerReference to force its way through; it just stops and surfaces the failure.

The CVO was initially set as the controller owner of the object and was removed by the rogue operator. Clearing out any such rogue operators as controllers may not stop them from clearing the CVO out again and continuing to fight in an endless loop, which can "destabilize the apiserver, thrash objects back-and-forth, or cause controller operations to hang".

This is an RHSSO operator issue.

However, the bug itself is about what we should do in such cases. Is bricking the CVO the desired outcome? Probably not. However, not respecting the API also does not sound like the ideal approach. Currently, everything works "as expected":

  1. The CVO is set as an owner and the controller
  2. Another operator replaces the CVO as the controller and kicks out the CVO as an owner - poor little CVO
  3. The CVO lost its rights and can't continue to manage the resource. This is propagated by:

The user-facing ClusterVersion conditions:

    - lastTransitionTime: "2025-11-18T04:52:21Z"
      message: 'Could not update customresourcedefinition "clusterserviceversions.operators.coreos.com"
        (649 of 901): the object is invalid, possibly due to local cluster configuration'
      reason: UpdatePayloadResourceInvalid
      status: "True"
      type: Failing
    - lastTransitionTime: "2025-06-09T13:07:08Z"
      message: 'Error while reconciling 4.18.13: some cluster configuration is invalid'
      reason: UpdatePayloadResourceInvalid
      status: "False"
      type: Progressing

The CVO logs include more information such as:

2024-09-03T14:11:19.672587865Z I0903 14:11:19.672572       1 sync_worker.go:1171] Update error 649 of 903: UpdatePayloadResourceInvalid Could not update customresourcedefinition "clusterserviceversions.operators.coreos.com" (649 of 903): the object is invalid, possibly due to local cluster configuration (*errors.StatusError: CustomResourceDefinition.apiextensions.k8s.io "clusterserviceversions.operators.coreos.com" is invalid: metadata.ownerReferences: Invalid value: []v1.OwnerReference{v1.OwnerReference{APIVersion:"config.openshift.io/v1", Kind:"ClusterServiceVersion", Name:"rhsso-operator.7.6.9-opr-002", UID:"00f0a902-a305-40bd-b277-2de22dca78ba", Controller:(*bool)(0xc1014fb039), BlockOwnerDeletion:(*bool)(nil)}, v1.OwnerReference{APIVersion:"config.openshift.io/v1", Kind:"ClusterVersion", Name:"version", UID:"6412f9f6-7ecf-4bfc-8277-813c9a4ef48d", Controller:(*bool)(0xc1014fb03a), BlockOwnerDeletion:(*bool)(nil)}}: Only one reference can have Controller set to true. Found "true" in references for ClusterServiceVersion/rhsso-operator.7.6.9-opr-002 and ClusterVersion/version)

We may stomp the rogue operator's changes to proceed, but most likely it won't stop them. A rogue operator may overwrite the CRD on startup or continuously. If continuously, it will only make it harder to detect the introduced situation while introducing a hidden regression in performance and potentially in functionality due to the operators continuously overwriting their changes.

From the proposal:

The Three Laws of Controllers

All controllers that manage collections of objects should obey the following
rules.

  1. Take ownership

    A controller should claim ownership of any objects it creates by adding a
    ControllerRef, and may also claim ownership of an object it didn't create,
    as long as the object has no existing ControllerRef (i.e. it is an orphan).

  2. Don't interfere

    A controller should not take any action (e.g. edit/scale/delete) on an object
    it does not own, except to adopt the object if allowed by the
    First Law.

  3. Don't share

    A controller should not count an object it does not own toward satisfying its
    desired state (e.g. a certain number of replicas), although it may include
    the object in plans to achieve its desired state (e.g. through adoption)
    as long as such plans do not conflict with the First or Second Laws.

The ControllerRef API has its purpose.


The CVO gets attributed the bug because it is simply vocal about the existing issue caused by a local cluster configuration and respects the API to not cause issues.

Removing the controllerRef from a rogue operator, who wants to forcibly manage the object, may introduce issues for that operator of an unknown impact. The CVO fighting with a rogue controller may introduce other issues. Leaving things as-is introduces a blocked CVO as the issue. A serious issue; however, it is communicated to the cluster administrator.


I am inclined towards the "we complain when there's a conflict, so the cluster-admin can dig in and report a bug against whoever falsely thought they were the controller" approach, provided we give actionable enough advice to the cluster administrators where to look next. Maybe Could not update customresourcedefinition "clusterserviceversions.operators.coreos.com" (649 of 901): the object is invalid, possibly due to local cluster configuration is not strong enough?

Alternatively, we may yield being the controller when someone forces us out in a live-cluster and adopt the object when it becomes an orphan; however, that smells like a Pandora's box.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @wking and @DavidHurta for the thorough review and the historical context, really appreciate it.

I agree that the current approach (keeping the rogue ref but clearing its controller flag) sits in an awkward middle ground. After reading your feedback, I see three possible directions:

Improve the error message - Keep the current CVO behavior (fail when there's a conflict), but make the error message more actionable so cluster-admins know exactly which operator is the rogue controller and can file a bug against it. This aligns with the "don't interfere" principle from the ControllerRef proposal.

CVO fully owns ownerReferences - When CVO manages a resource, it takes complete ownership of ownerReferences and removes rogue entries entirely rather than trying to merge them.

Close this PR - The root cause belongs in the rogue operator (RHSSO in this case) and this isn't something CVO should work around.

Which direction would you prefer? Happy to update the PR accordingly.

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

Labels

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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants