Skip to content

OCPBUGS-100179: fix forward controller FilterFunc and finalizer removal - #450

Open
emmahone wants to merge 2 commits into
openshift:masterfrom
emmahone:OCPBUGS-100179-fix-forward-controller-filter
Open

OCPBUGS-100179: fix forward controller FilterFunc and finalizer removal#450
emmahone wants to merge 2 commits into
openshift:masterfrom
emmahone:OCPBUGS-100179-fix-forward-controller-filter

Conversation

@emmahone

@emmahone emmahone commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Two related defects in legacyImagePullSecretController leave dockercfg
secrets permanently stuck with an openshift.io/legacy-token finalizer after
namespace deletion, causing namespaces to hang in Terminating forever.

This is distinct from OCPBUGS-52193 / PR #380 (which fixed the
managementState: Removed scenario): the customer's cluster has
managementState: Managed so the rollback controller added by #380 never
activates, and the forward controller's own FilterFunc is the defect.

Defect 1 — FilterFunc silently drops transitioning secrets (new fix)

The informer FilterFunc required openshift.io/token-secret.name to be
present. Secrets that transitioned to the "bound" auth type have this
annotation removed (they carry openshift.io/internal-registry-auth-token.binding: bound
instead), so they are silently dropped before ever reaching the workqueue.
Once namespace deletion sets deletionTimestamp on these secrets, sync() is
never called, the finalizer is never cleared, and the namespace hangs.

Fix: extend the FilterFunc to also pass secrets whose deletionTimestamp
is set and that still carry the openshift.io/legacy-token finalizer,
regardless of the annotation. The existing deletion path in sync() already
handles the absent-annotation case correctly — it skips token-secret deletion
(len(t)==0) and proceeds straight to finalizer removal.

Defect 2 — Apply with nil finalizers does not clear the field (cleanup fix)

The deletion path built a filtered finalizers slice and called Apply with
it. When openshift.io/legacy-token was the only finalizer, the slice was
nil; the applyconfigurations field is tagged omitempty, so nil serialises
as absent from the patch body. SSA therefore does not touch the finalizers
field and the finalizer persists.

Fix: use a JSON Patch (identical to the rollback controller's approach)
which directly removes the specific finalizer by index and is not subject to
omitempty serialisation. The "test" op before the "remove" ensures safe
concurrent writes by failing fast if the cache is stale.

Fixes: https://issues.redhat.com/browse/OCPBUGS-100179

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup of legacy image-pull secrets during deletion.
    • Secrets are now properly removed even when their legacy token annotation has already been removed.
    • Prevented deletion from becoming stuck when cleanup metadata is already absent or has changed.

The legacyImagePullSecretController has two related defects that together
cause dockercfg secrets to remain stuck with an openshift.io/legacy-token
finalizer after their namespace's deletionTimestamp is set, leaving namespaces
permanently in Terminating.

**Defect 1 — FilterFunc silently drops transitioning secrets (new fix)**

The informer FilterFunc required the openshift.io/token-secret.name annotation
to be present. Secrets that have already transitioned to the "bound" auth type
(annotation removed, openshift.io/internal-registry-auth-token.binding: bound)
but still carry the legacy-token finalizer were therefore never queued for
reconciliation. Once a namespace is deleted and deletionTimestamp is set on
these secrets, sync() is never invoked, the finalizer is never cleared, and
the namespace hangs indefinitely.

Fix: extend the FilterFunc to also pass secrets whose deletionTimestamp is
set and that still carry the openshift.io/legacy-token finalizer, regardless
of the token-secret.name annotation. The existing sync() deletion path already
handles the absent-annotation case correctly (len(t)==0 skips token deletion
and proceeds straight to finalizer removal).

**Defect 2 — Apply with nil finalizers does not clear the field (cleanup fix)**

The deletion path built a filtered finalizers slice and called Apply with it.
When openshift.io/legacy-token was the only finalizer, the slice was nil; the
applyconfigurations field is tagged omitempty, so nil serialises as absent from
the patch body. SSA therefore does not touch the finalizers field and the
finalizer persists.

Fix: use a JSON Patch (identical to the rollback controller's approach) which
directly removes the specific finalizer by index and is not subject to
omitempty serialisation. The "test" op before the "remove" ensures safe
concurrent writes by failing fast if the cache is stale.

Fixes: https://issues.redhat.com/browse/OCPBUGS-100179
@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 6, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@emmahone: This pull request references Jira Issue OCPBUGS-100179, which is invalid:

  • expected the bug to target either version "5.0." or "openshift-5.0.", but it targets "4.20" instead

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

Two related defects in legacyImagePullSecretController leave dockercfg
secrets permanently stuck with an openshift.io/legacy-token finalizer after
namespace deletion, causing namespaces to hang in Terminating forever.

This is distinct from OCPBUGS-52193 / PR #380 (which fixed the
managementState: Removed scenario): the customer's cluster has
managementState: Managed so the rollback controller added by #380 never
activates, and the forward controller's own FilterFunc is the defect.

Defect 1 — FilterFunc silently drops transitioning secrets (new fix)

The informer FilterFunc required openshift.io/token-secret.name to be
present. Secrets that transitioned to the "bound" auth type have this
annotation removed (they carry openshift.io/internal-registry-auth-token.binding: bound
instead), so they are silently dropped before ever reaching the workqueue.
Once namespace deletion sets deletionTimestamp on these secrets, sync() is
never called, the finalizer is never cleared, and the namespace hangs.

Fix: extend the FilterFunc to also pass secrets whose deletionTimestamp
is set and that still carry the openshift.io/legacy-token finalizer,
regardless of the annotation. The existing deletion path in sync() already
handles the absent-annotation case correctly — it skips token-secret deletion
(len(t)==0) and proceeds straight to finalizer removal.

Defect 2 — Apply with nil finalizers does not clear the field (cleanup fix)

The deletion path built a filtered finalizers slice and called Apply with
it. When openshift.io/legacy-token was the only finalizer, the slice was
nil; the applyconfigurations field is tagged omitempty, so nil serialises
as absent from the patch body. SSA therefore does not touch the finalizers
field and the finalizer persists.

Fix: use a JSON Patch (identical to the rollback controller's approach)
which directly removes the specific finalizer by index and is not subject to
omitempty serialisation. The "test" op before the "remove" ensures safe
concurrent writes by failing fast if the cache is stale.

Fixes: https://issues.redhat.com/browse/OCPBUGS-100179

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 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@emmahone, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 63214e15-9813-4c50-beec-4dcb1e4f5c55

📥 Commits

Reviewing files that changed from the base of the PR and between dc3b458 and cf05e42.

📒 Files selected for processing (1)
  • pkg/internalregistry/controllers/legacy_image_pull_secret_controller_test.go

Walkthrough

The controller now enqueues deleting Dockercfg secrets that retain the legacy-token finalizer and removes that finalizer with a JSON Patch. Tests cover normal, transitioned, completed, and stale-cache deletion paths.

Changes

Legacy finalizer cleanup

Layer / File(s) Summary
Deletion event filtering and JSON Patch cleanup
pkg/internalregistry/controllers/legacy_image_pull_secret_controller.go
The event filter accepts deleting secrets with the legacy-token finalizer even without the token annotation. Finalizer removal uses a JSON Patch test/remove operation.
Deletion-path test coverage
pkg/internalregistry/controllers/legacy_image_pull_secret_controller_test.go
Table-driven tests cover transitioned secrets, annotated deletion, already-removed finalizers, and stale-cache patch failures.

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

Sequence Diagram(s)

sequenceDiagram
  participant SecretEventFilter
  participant LegacyImagePullSecretController
  participant SecretLister
  participant KubernetesAPI
  SecretEventFilter->>LegacyImagePullSecretController: Enqueue deleting Dockercfg secret
  LegacyImagePullSecretController->>SecretLister: Read cached secret
  LegacyImagePullSecretController->>KubernetesAPI: Apply test/remove JSON Patch
  KubernetesAPI-->>LegacyImagePullSecretController: Return patch result
Loading
🚥 Pre-merge checks | ✅ 13 | ❌ 2

❌ Failed checks (2 warnings)

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.
Test Structure And Quality ⚠️ Warning The added test uses context-free t.Fatal(err) for indexer.Add and Secret.Get failures, so these assertions do not identify the failed operation. Add operation-specific messages, such as "failed to add cached secret to indexer: %v" and "failed to get secret after sync: %v".
✅ Passed checks (13 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 controller filter and finalizer removal fixes described in the changeset.
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 added test uses a static function name and four literal t.Run names; the changed file has no Ginkgo It, Describe, Context, or When titles and no dynamic title values.
Microshift Test Compatibility ✅ Passed The added test is a standard Go t.Run unit test, not a Ginkgo e2e test, and it references no MicroShift-incompatible APIs or resources.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The added test is a standard Go unit test using testing.T and fake clients; it adds no Ginkgo e2e test or multi-node/HA assumption.
Topology-Aware Scheduling Compatibility ✅ Passed The diff only changes a Secret informer/controller and its tests; searches found no Deployment, Pod, replica, affinity, topology spread, node selector, toleration, or PDB scheduling constraints.
Ote Binary Stdout Contract ✅ Passed The PR changes only controller logic and a unit test; added code has no stdout writes, and existing klog calls are outside OTE process-level setup.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added test uses standard testing.T with a fake Kubernetes client. It has no Ginkgo constructs, IPv4 assumptions, URLs, or external connectivity.
No-Weak-Crypto ✅ Passed The PR adds no MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, custom crypto, or secret-value comparison; JSON Patch compares only a fixed finalizer string.
Container-Privileges ✅ Passed The patch changes only two Go files. It adds no container or Kubernetes manifests and no privilege settings such as privileged, hostPID, SYS_ADMIN, or allowPrivilegeEscalation.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no production logging. Existing logs expose only a workqueue key and controller name; tests use non-sensitive placeholders.
✨ 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

Copy link
Copy Markdown
Contributor

@emmahone: This pull request references Jira Issue OCPBUGS-100179, which is invalid:

  • expected the bug to target only the "5.0.0" version, but multiple target versions were 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.

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.

@openshift-ci
openshift-ci Bot requested review from p0lyn0mial and prabhapa August 6, 2026 18:39
@openshift-ci

openshift-ci Bot commented Aug 6, 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 xueqzhan 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 the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Aug 6, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

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

Summary

Two related defects in legacyImagePullSecretController leave dockercfg
secrets permanently stuck with an openshift.io/legacy-token finalizer after
namespace deletion, causing namespaces to hang in Terminating forever.

This is distinct from OCPBUGS-52193 / PR #380 (which fixed the
managementState: Removed scenario): the customer's cluster has
managementState: Managed so the rollback controller added by #380 never
activates, and the forward controller's own FilterFunc is the defect.

Defect 1 — FilterFunc silently drops transitioning secrets (new fix)

The informer FilterFunc required openshift.io/token-secret.name to be
present. Secrets that transitioned to the "bound" auth type have this
annotation removed (they carry openshift.io/internal-registry-auth-token.binding: bound
instead), so they are silently dropped before ever reaching the workqueue.
Once namespace deletion sets deletionTimestamp on these secrets, sync() is
never called, the finalizer is never cleared, and the namespace hangs.

Fix: extend the FilterFunc to also pass secrets whose deletionTimestamp
is set and that still carry the openshift.io/legacy-token finalizer,
regardless of the annotation. The existing deletion path in sync() already
handles the absent-annotation case correctly — it skips token-secret deletion
(len(t)==0) and proceeds straight to finalizer removal.

Defect 2 — Apply with nil finalizers does not clear the field (cleanup fix)

The deletion path built a filtered finalizers slice and called Apply with
it. When openshift.io/legacy-token was the only finalizer, the slice was
nil; the applyconfigurations field is tagged omitempty, so nil serialises
as absent from the patch body. SSA therefore does not touch the finalizers
field and the finalizer persists.

Fix: use a JSON Patch (identical to the rollback controller's approach)
which directly removes the specific finalizer by index and is not subject to
omitempty serialisation. The "test" op before the "remove" ensures safe
concurrent writes by failing fast if the cache is stale.

Fixes: https://issues.redhat.com/browse/OCPBUGS-100179

Summary by CodeRabbit

  • Bug Fixes
  • Improved cleanup of legacy image-pull secrets during deletion.
  • Secrets are now properly removed even when their legacy token annotation has already been removed.
  • Prevented deletion from becoming stuck when cleanup metadata is already absent or has changed.

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-robot openshift-ci-robot removed the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Aug 6, 2026
@emmahone

emmahone commented Aug 6, 2026

Copy link
Copy Markdown
Author

/jira refresh

@openshift-ci-robot

Copy link
Copy Markdown
Contributor

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

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

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

🧹 Nitpick comments (1)
pkg/internalregistry/controllers/legacy_image_pull_secret_controller_test.go (1)

97-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the informer filter path.

These cases call sync directly. They do not verify that the changed FilterFunc enqueues a deleting Dockercfg secret with the legacy finalizer and without openshift.io/token-secret.name.

Add a controller-level event test. Send that secret through the informer. Assert that the queue receives its namespace key.

🤖 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/internalregistry/controllers/legacy_image_pull_secret_controller_test.go`
around lines 97 - 101, Extend the tests around legacyImagePullSecretController
with a controller-level informer event case that sends a deleting Dockercfg
secret carrying the legacy finalizer and no openshift.io/token-secret.name
through the informer, then assert the work queue receives its namespace/name
key. Keep the existing direct sync cases unchanged and exercise the changed
FilterFunc rather than invoking sync directly.
🤖 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.

Nitpick comments:
In
`@pkg/internalregistry/controllers/legacy_image_pull_secret_controller_test.go`:
- Around line 97-101: Extend the tests around legacyImagePullSecretController
with a controller-level informer event case that sends a deleting Dockercfg
secret carrying the legacy finalizer and no openshift.io/token-secret.name
through the informer, then assert the work queue receives its namespace/name
key. Keep the existing direct sync cases unchanged and exercise the changed
FilterFunc rather than invoking sync directly.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 3325f097-e87e-4712-abd3-b76ccb378c63

📥 Commits

Reviewing files that changed from the base of the PR and between 5631cf4 and dc3b458.

📒 Files selected for processing (2)
  • pkg/internalregistry/controllers/legacy_image_pull_secret_controller.go
  • pkg/internalregistry/controllers/legacy_image_pull_secret_controller_test.go

@openshift-ci

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants