Skip to content

OCPBUGS-84957: Skip controller ownerReference on CRDs - #3082

Open
dlom wants to merge 1 commit into
openshift:masterfrom
dlom:OCPBUGS-84957
Open

OCPBUGS-84957: Skip controller ownerReference on CRDs#3082
dlom wants to merge 1 commit into
openshift:masterfrom
dlom:OCPBUGS-84957

Conversation

@dlom

@dlom dlom commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Why

When CNO sets a controller ownerReference on CRDs (e.g. FRRConfiguration, BGPPeer),
two problems arise:

  1. Data loss risk: If the owning Network CR is deleted, Kubernetes garbage
    collection cascades to the CRD, which in turn destroys all CRs of that type
    cluster-wide.
  2. Ownership conflict: Kubernetes only allows a single controller
    ownerReference per object. Other operators (e.g. MetalLB installed via
    ClusterExtension/boxcutter) may legitimately need controller ownership of
    the same CRDs, causing AlreadyOwnedError failures.

xref: OCPBUGS-84957

What

  • Add an isCRD() helper that checks for apiextensions.k8s.io group +
    CustomResourceDefinition kind.
  • Skip SetControllerReference for CRD objects in the operconfig reconcile
    loop. Non-CRD resources continue to receive controller ownerReferences as
    before.

Testing

Unit tests (added in this PR):

  • TestIsCRD: verifies the helper correctly identifies CRDs by group+kind and
    rejects non-CRD resources including those with the same Kind in a different
    API group.
  • TestSetControllerReferenceSkipsCRDs: integration-style test that confirms
    Deployments receive a controller ownerReference while CRDs do not.
$ go test ./pkg/controller/operconfig/ -run 'TestIsCRD|TestSetControllerReferenceSkipsCRDs' -v
--- PASS: TestSetControllerReferenceSkipsCRDs/Deployment_gets_controller_ownerReference
--- PASS: TestSetControllerReferenceSkipsCRDs/CRD_does_not_get_controller_ownerReference
--- PASS: TestIsCRD/apiextensions_CRD
--- PASS: TestIsCRD/non-CRD_resource_with_same_Kind_in_different_group
--- PASS: TestIsCRD/Deployment
PASS
ok  github.com/openshift/cluster-network-operator/pkg/controller/operconfig  0.049s

E2E: This repo does not maintain in-tree e2e tests. E2e coverage is provided
by the OpenShift CI e2e-aws-ovn, e2e-gcp-ovn, and e2e-metal-ipi lanes
that run the full openshift-tests suite against a cluster with CNO deployed.
The change is a conditional skip of one SetControllerReference call — the
existing CI lanes validate that CNO continues to reconcile and that no operand
regressions occur. Targeted e2e verification of CRD ownership semantics would
require a multi-operator fixture (CNO + an external CRD claimant) that is not
available in the standard CI environment.

@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/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. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 21, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@dlom: This pull request references Jira Issue OCPBUGS-84957, 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:

CRDs should not receive controller ownerReferences because GC-deleting a CRD destroys all its associated CRs (instant data loss), and also because other controllers may legitimately claim ownership of them.

xref: OCPBUGS-84957

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 Jul 21, 2026

Copy link
Copy Markdown

Walkthrough

The operconfig controller now excludes CustomResourceDefinition objects from controller ownerReference assignment, adds GroupVersionKind-based CRD detection, updates related reconciliation comments, and introduces tests for detection and ownership behavior.

Changes

CRD ownership handling

Layer / File(s) Summary
CRD detection and ownership logic
pkg/controller/operconfig/operconfig_controller.go
Adds isCRD, excludes CRDs from controller ownerReferences, and documents the garbage-collection behavior.
Ownership behavior tests
pkg/controller/operconfig/operconfig_controller_test.go
Tests CRD detection and verifies ownerReferences for CRD and non-CRD objects.

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

Suggested labels: jira/valid-reference

Suggested reviewers: pperiyasamy, arghosh93


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (2 errors)

Check name Status Explanation Resolution
Pr Quality ❌ Error Description has Why/What/Testing and a bug link, but this behavioral change lacks any upgrade/rollback consideration. Add a brief upgrade/rollback note, e.g. that rollback is safe and the change only skips controller refs on CRDs.
E2e Tests For Feature Changes ❌ Error This fixes CRD ownerReference behavior in pkg/ and touches no test/e2e/ files; the PR description also lacks explicit e2e job pass status. Add/modify test/e2e/ coverage or document why e2e is infeasible in the PR, and state the CI lanes/jobs plus which passed before re-requesting review.
✅ Passed checks (22 passed)
Check name Status Explanation
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.
Commit Message Quality ✅ Passed One non-merge commit: scoped subject is concise, body explains why the CRD skip is needed, and no rule violations appear.
Unit Tests For Go Changes ✅ Passed Production Go changed in operconfig_controller.go, and a new corresponding test file operconfig_controller_test.go was added.
Rbac Least Privilege ✅ Passed PR changes only touch two Go files; no YAML under bindata/ or manifests/ was modified, so no RBAC rules changed.
Docs For Feature And Behavior Changes ✅ Passed This is a bug fix that narrows controller ownership for CRDs; no docs/ files were added or modified, and the check treats bug fixes as pass.
Stale Project Docs And Config ✅ Passed No docs/config files reference CRD ownerReferences or the changed operconfig behavior; .coderabbit.yaml and docs/** remain accurate.
Go And Test Code Quality ✅ Passed The patch adds CRD-skipping logic and tests without introducing new logging, bare returns, duration literals, shadowing bugs, or test anti-patterns.
Ai-Generated Code Smell ✅ Passed No obvious comment slop, AI/tool references, or disproportionate test bloat; the new CRD skip logic and tests are tightly scoped to the change.
Stable And Deterministic Test Names ✅ Passed Changed tests use only static t.Run names; no dynamic data, timestamps, or generated identifiers appear in test titles.
Test Structure And Quality ✅ Passed PASS: These are plain table-driven unit tests (no Ginkgo/cluster waits/resources), each subtest checks one behavior, and failures include clear messages.
Microshift Test Compatibility ✅ Passed The added tests are plain Go unit tests, not Ginkgo e2e, and they only exercise CRD detection/controller refs without unsupported OpenShift APIs.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds plain Go unit tests, not Ginkgo e2e tests, and the changed code contains no multi-node or SNO-specific assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed Only ownerReference/CRD detection logic changed; no replicas, affinity, nodeSelector, tolerations, or topology-spread code was added.
Ote Binary Stdout Contract ✅ Passed No main/init/TestMain/RunSpecs or top-level initializers write to stdout in touched files; added logs are inside reconcile/tests, so the stdout contract is unaffected.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo/e2e tests were added; the added tests are unit tests and contain no IPv4 or external connectivity assumptions.
No-Weak-Crypto ✅ Passed No MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons found; changes only guard CRD ownerReferences.
Container-Privileges ✅ Passed PR only changes Go controller/test files; no manifests or privileged/securityContext fields were added.
No-Sensitive-Data-In-Logs ✅ Passed No new logs expose secrets/PII/internal hosts; the PR only changes ownerReference logic and adds tests, with no sensitive logging added.
Title check ✅ Passed The title is imperative, concise, and accurately describes the CRD ownerReference change.
Description check ✅ Passed The description matches the change and explains the CRD ownerReference skip and tests.
✨ 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.

@dlom

dlom commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

/jira refresh

@openshift-ci
openshift-ci Bot requested review from arghosh93 and pperiyasamy July 21, 2026 18:49
@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@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 Jul 21, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@dlom: This pull request references Jira Issue OCPBUGS-84957, 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 ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

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.

@dlom dlom changed the title OCPBUGS-84957: Skip controller ownerReference on CRDs operconfig: Skip controller ownerReference on CRDs Jul 21, 2026
@openshift-ci-robot openshift-ci-robot removed 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. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jul 21, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@dlom: No Jira issue is referenced in the title of this pull request.
To reference a jira issue, add 'XYZ-NNN:' to the title of this pull request and request another refresh with /jira refresh.

Details

In response to this:

Why

When CNO sets a controller ownerReference on CRDs (e.g. FRRConfiguration, BGPPeer),
two problems arise:

  1. Data loss risk: If the owning Network CR is deleted, Kubernetes garbage
    collection cascades to the CRD, which in turn destroys all CRs of that type
    cluster-wide.
  2. Ownership conflict: Kubernetes only allows a single controller
    ownerReference per object. Other operators (e.g. MetalLB installed via
    ClusterExtension/boxcutter) may legitimately need controller ownership of
    the same CRDs, causing AlreadyOwnedError failures.

xref: OCPBUGS-84957

What

  • Add an isCRD() helper that checks for apiextensions.k8s.io group +
    CustomResourceDefinition kind.
  • Skip SetControllerReference for CRD objects in the operconfig reconcile
    loop. Non-CRD resources continue to receive controller ownerReferences as
    before.

Testing

Unit tests (added in this PR):

  • TestIsCRD: verifies the helper correctly identifies CRDs by group+kind and
    rejects non-CRD resources including those with the same Kind in a different
    API group.
  • TestSetControllerReferenceSkipsCRDs: integration-style test that confirms
    Deployments receive a controller ownerReference while CRDs do not.
$ go test ./pkg/controller/operconfig/ -run 'TestIsCRD|TestSetControllerReferenceSkipsCRDs' -v
--- PASS: TestSetControllerReferenceSkipsCRDs/Deployment_gets_controller_ownerReference
--- PASS: TestSetControllerReferenceSkipsCRDs/CRD_does_not_get_controller_ownerReference
--- PASS: TestIsCRD/apiextensions_CRD
--- PASS: TestIsCRD/non-CRD_resource_with_same_Kind_in_different_group
--- PASS: TestIsCRD/Deployment
PASS
ok  github.com/openshift/cluster-network-operator/pkg/controller/operconfig  0.049s

E2E: This repo does not maintain in-tree e2e tests. E2e coverage is provided
by the OpenShift CI e2e-aws-ovn, e2e-gcp-ovn, and e2e-metal-ipi lanes
that run the full openshift-tests suite against a cluster with CNO deployed.
The change is a conditional skip of one SetControllerReference call — the
existing CI lanes validate that CNO continues to reconcile and that no operand
regressions occur. Targeted e2e verification of CRD ownership semantics would
require a multi-operator fixture (CNO + an external CRD claimant) that is not
available in the standard CI environment.

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.

GC-deleting a CRD destroys all its associated CRs (instant data loss),
and other operators (e.g. MetalLB via ClusterExtension/boxcutter) may
legitimately claim controller ownership of the same CRDs, which
conflicts because Kubernetes only allows a single controller
ownerReference per object.

Skip CRDs when setting controller ownerReferences in the operconfig
reconcile loop. Non-CRD resources continue to be owned as before.

xref: OCPBUGS-84957
@dlom

dlom commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

/retitle OCPBUGS-84957: Skip controller ownerReference on CRDs

@openshift-ci openshift-ci Bot changed the title operconfig: Skip controller ownerReference on CRDs OCPBUGS-84957: Skip controller ownerReference on CRDs Jul 21, 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. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jul 21, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@dlom: This pull request references Jira Issue OCPBUGS-84957, which is valid.

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 POST, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

Why

When CNO sets a controller ownerReference on CRDs (e.g. FRRConfiguration, BGPPeer),
two problems arise:

  1. Data loss risk: If the owning Network CR is deleted, Kubernetes garbage
    collection cascades to the CRD, which in turn destroys all CRs of that type
    cluster-wide.
  2. Ownership conflict: Kubernetes only allows a single controller
    ownerReference per object. Other operators (e.g. MetalLB installed via
    ClusterExtension/boxcutter) may legitimately need controller ownership of
    the same CRDs, causing AlreadyOwnedError failures.

xref: OCPBUGS-84957

What

  • Add an isCRD() helper that checks for apiextensions.k8s.io group +
    CustomResourceDefinition kind.
  • Skip SetControllerReference for CRD objects in the operconfig reconcile
    loop. Non-CRD resources continue to receive controller ownerReferences as
    before.

Testing

Unit tests (added in this PR):

  • TestIsCRD: verifies the helper correctly identifies CRDs by group+kind and
    rejects non-CRD resources including those with the same Kind in a different
    API group.
  • TestSetControllerReferenceSkipsCRDs: integration-style test that confirms
    Deployments receive a controller ownerReference while CRDs do not.
$ go test ./pkg/controller/operconfig/ -run 'TestIsCRD|TestSetControllerReferenceSkipsCRDs' -v
--- PASS: TestSetControllerReferenceSkipsCRDs/Deployment_gets_controller_ownerReference
--- PASS: TestSetControllerReferenceSkipsCRDs/CRD_does_not_get_controller_ownerReference
--- PASS: TestIsCRD/apiextensions_CRD
--- PASS: TestIsCRD/non-CRD_resource_with_same_Kind_in_different_group
--- PASS: TestIsCRD/Deployment
PASS
ok  github.com/openshift/cluster-network-operator/pkg/controller/operconfig  0.049s

E2E: This repo does not maintain in-tree e2e tests. E2e coverage is provided
by the OpenShift CI e2e-aws-ovn, e2e-gcp-ovn, and e2e-metal-ipi lanes
that run the full openshift-tests suite against a cluster with CNO deployed.
The change is a conditional skip of one SetControllerReference call — the
existing CI lanes validate that CNO continues to reconcile and that no operand
regressions occur. Targeted e2e verification of CRD ownership semantics would
require a multi-operator fixture (CNO + an external CRD claimant) that is not
available in the standard CI environment.

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.

@dlom

dlom commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

/retest

3 similar comments
@dlom

dlom commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@dlom

dlom commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@dlom

dlom commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@dlom: The following test 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/5.0-upgrade-from-stable-4.22-e2e-aws-ovn-upgrade 4868fea link false /test 5.0-upgrade-from-stable-4.22-e2e-aws-ovn-upgrade

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants