Skip to content

CNTRLPLANE-3375: bugfix: make switched controller clear status conditions on delegate controller shutdown#955

Open
everettraven wants to merge 1 commit into
openshift:masterfrom
everettraven:bugfix/switched-controller-stale-status-condition
Open

CNTRLPLANE-3375: bugfix: make switched controller clear status conditions on delegate controller shutdown#955
everettraven wants to merge 1 commit into
openshift:masterfrom
everettraven:bugfix/switched-controller-stale-status-condition

Conversation

@everettraven

@everettraven everettraven commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • When a switched-off delegate shuts down, stale degraded status conditions are now cleared to prevent lingering error states.
    • Enhanced failure handling and reporting if clearing degraded conditions doesn’t succeed.
  • Tests
    • Added coverage to verify degraded conditions are cleared when the controller is switched off.

@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 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 Jul 23, 2026
@everettraven

Copy link
Copy Markdown
Contributor Author

/payload-aggregate periodic-ci-openshift-cluster-authentication-operator-release-5.0-periodics-e2e-azure-external-oidc-upstream-parity 10

@openshift-ci

openshift-ci Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@everettraven: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-cluster-authentication-operator-release-5.0-periodics-e2e-azure-external-oidc-upstream-parity

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/9c54e180-86bf-11f1-9d5b-1744dbf73ad8-0

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Walkthrough

The switched controller now optionally clears delegate-owned degraded conditions through Server-Side Apply when switching off. The OAuth clients controller enables this behavior, and tests verify the field manager and empty conditions configuration.

Changes

Delegate condition cleanup

Layer / File(s) Summary
Configure and apply delegate status cleanup
pkg/controllers/switchedcontroller/switched_controller.go, pkg/controllers/oauthclientscontroller/oauthclientscontroller.go
The switched controller accepts a cleanup flag, stores the operator client, and applies an empty OperatorStatus with the delegate field manager during shutdown; the OAuth clients controller enables the flag.
Validate applied status conditions
pkg/controllers/switchedcontroller/switched_controller_test.go
Test helpers record and synchronize status applications, while the switch-off test verifies the expected field manager and empty conditions list.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SwitchedController
  participant DelegateController
  participant OperatorClient
  SwitchedController->>DelegateController: cancel delegate context
  SwitchedController->>OperatorClient: ApplyOperatorStatus with empty OperatorStatus
  OperatorClient-->>SwitchedController: return apply result
Loading

Suggested reviewers: ardaguclu, ibihim

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 All touched test names are static, descriptive Test... functions; no Ginkgo titles, timestamps, UUIDs, or other dynamic values appear.
Test Structure And Quality ✅ Passed The new test is a focused unit test, uses explicit timeouts for async waits, cancels the controller path on switch-off, and includes specific failure messages.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the added test is a plain testing.T unit test and contains no MicroShift-specific APIs/tags.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the changes are Go unit tests using fake clients and no multi-node/SNO assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed The changes only adjust switched-controller status handling and tests; no replicas, affinity, node selectors, tolerations, or PDBs were introduced.
Ote Binary Stdout Contract ✅ Passed Touched files add no process-level stdout writes; searches found no main/init/TestMain/BeforeSuite setup prints, only test-local t.Fatalf/err usage.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The new test is a plain unit test using testing.T and fake clients; it adds no Ginkgo e2e coverage, IPv4-only assumptions, or external network calls.
No-Weak-Crypto ✅ Passed No MD5/SHA1/DES/RC4/3DES/Blowfish/ECB or secret-comparison code was added; the touched changes only adjust controller status logic, and existing randomness uses crypto/rand.
Container-Privileges ✅ Passed Only Go controller/test code changed; no manifest or pod security fields like privileged, hostNetwork, hostPID, or allowPrivilegeEscalation were added.
No-Sensitive-Data-In-Logs ✅ Passed No new log statements or secret-bearing fields were added; changes only return errors and assert test behavior.
Title check ✅ Passed The title clearly and accurately summarizes the main change: clearing switched controller status conditions during delegate shutdown.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
openshift-ci Bot requested review from ardaguclu and ibihim July 23, 2026 17:56
@openshift-ci

openshift-ci Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/controllers/switchedcontroller/switched_controller.go (1)

100-119: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Clearing delegate conditions can race with an in-flight delegate sync, and a failed clear is never retried.

Two related gaps in this shutdown path:

  1. c.switchContextCancel() only requests cancellation; the delegate goroutine started with go ...Run(c.switchContext, 1) (line 94) is not waited on. If the delegate is mid-sync (or picks up one more queued item before observing ctx.Done()), it can call its own WithSyncDegradedOnError and re-set the degraded condition after this clear runs, silently reintroducing the stale condition this PR is meant to fix.
  2. Once this case executes, c.switchContext is set to nil regardless of whether ApplyOperatorStatus below succeeds. On the next sync, noContext is true, which routes to the no-op branch (Line 100) — so a failed apply (e.g., transient API error) is never retried; the stale degraded condition can persist indefinitely until the delegate is switched back on.

Consider tracking delegate-goroutine completion (e.g. a done channel/sync.WaitGroup) and only issuing the clear once the delegate has actually stopped, plus tracking a "conditions cleared" flag so a failed apply can be retried on a subsequent sync (rather than being a one-shot transition).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controllers/switchedcontroller/switched_controller.go` around lines 100 -
119, Update the switched-controller shutdown flow around switchContextCancel and
the delegate goroutine running Run to track delegate completion, waiting for it
to stop before clearing conditions. Track whether delegate conditions were
successfully cleared, retain the shutdown state when ApplyOperatorStatus fails,
and retry the clear on subsequent syncs until it succeeds; only transition to
the no-op state after confirmed cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/controllers/switchedcontroller/switched_controller_test.go`:
- Around line 493-497: Update the applyStatusCalls assertion in the switched
controller test to require exactly one call, rejecting both zero and multiple
calls before indexing the slice. Preserve the existing failure message context
and only access applyStatusCalls[0] after this validation.

---

Outside diff comments:
In `@pkg/controllers/switchedcontroller/switched_controller.go`:
- Around line 100-119: Update the switched-controller shutdown flow around
switchContextCancel and the delegate goroutine running Run to track delegate
completion, waiting for it to stop before clearing conditions. Track whether
delegate conditions were successfully cleared, retain the shutdown state when
ApplyOperatorStatus fails, and retry the clear on subsequent syncs until it
succeeds; only transition to the no-op state after confirmed cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: dccd4add-b168-42ae-a054-1a953eea1f11

📥 Commits

Reviewing files that changed from the base of the PR and between 8c68999 and 5d13d1f.

📒 Files selected for processing (2)
  • pkg/controllers/switchedcontroller/switched_controller.go
  • pkg/controllers/switchedcontroller/switched_controller_test.go

Comment thread pkg/controllers/switchedcontroller/switched_controller_test.go Outdated
@ShazaAldawamneh

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-agnostic
/test e2e-agnostic-upgrade
/test e2e-console-login
/test e2e-gcp-operator-disruptive
/test e2e-oidc
/test e2e-operator

…controller shutdown

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
@everettraven
everettraven force-pushed the bugfix/switched-controller-stale-status-condition branch from 13bf582 to 03fc95d Compare July 24, 2026 12:40
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2026
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@everettraven: 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/e2e-agnostic 13bf582 link true /test e2e-agnostic

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.

@everettraven everettraven changed the title WIP: bugfix: make switched controller clear status conditions on delegate controller shutdown CNTRLPLANE-3375: bugfix: make switched controller clear status conditions on delegate controller shutdown Jul 24, 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 Jul 24, 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 Jul 24, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@everettraven: This pull request references CNTRLPLANE-3375 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 story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary by CodeRabbit

  • Bug Fixes
  • When a switched-off delegate shuts down, stale degraded status conditions are now cleared to prevent lingering error states.
  • Enhanced failure handling and reporting if clearing degraded conditions doesn’t succeed.
  • Tests
  • Added coverage to verify degraded conditions are cleared when the controller is switched off.

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.

@everettraven

Copy link
Copy Markdown
Contributor Author

/payload-aggregate periodic-ci-openshift-cluster-authentication-operator-release-5.0-periodics-e2e-azure-external-oidc-upstream-parity 10

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@everettraven: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-cluster-authentication-operator-release-5.0-periodics-e2e-azure-external-oidc-upstream-parity

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/e0b25f80-876c-11f1-99da-85f49dc1b7d9-0

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

Labels

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.

3 participants