Skip to content

fix(namespace-management): enqueue the instance when consent is withdrawn - #1613

Open
Gabrielandre02 wants to merge 1 commit into
redhat-developer:masterfrom
Gabrielandre02:nsmgmt-enqueue-on-consent-withdrawal
Open

Gabrielandre02 wants to merge 1 commit into
redhat-developer:masterfrom
Gabrielandre02:nsmgmt-enqueue-on-consent-withdrawal

Conversation

@Gabrielandre02

Copy link
Copy Markdown
Contributor

What does this PR do?

When a NamespaceManagement CR is deleted, the Argo CD instance it named is never enqueued. The delete predicate returns false on every path, so the mapper never runs. Retargeting .spec.managedBy has the same problem whenever the predicate skips or fails its own cleanup, for example when the managing namespace has a matching managed-by label. Stale grants, such as the Image Updater manager Role and RoleBinding in the target namespace, then stay until some unrelated reconcile.

With this change:

  • delete enqueues whenever the CR named an instance.
  • update enqueues whenever .spec.managedBy changes, whatever the predicate cleanup did.

The reconcile already rebuilds consent and prunes what is no longer allowed, so it removes the stale RBAC. Status-only updates are still filtered out so the reconcile's own status writes don't loop.

Fixes #1530

PR acceptance criteria:

  • Documentation was updated and verified using make serve-docs: not applicable, there is no user-facing change.
  • Unit tests were updated
  • E2E tests were updated: not added, the event path is covered by unit tests.

What type of PR is this?

/kind bug

Special notes to the reviewer:

The tests are in a new file, namespaceManagement_events_test.go:

  • One test sends delete and update events through namespaceManagementFilterPredicate(), including the matching managed-by label case and a status-only update. The four withdrawal cases fail on master.
  • The other test grants Image Updater RBAC through a NamespaceManagement CR, deletes the CR, runs the consent and RBAC steps of the reconcile again, and checks that the Role and RoleBinding are gone.

I also flipped the existing HandleNamespaceManagementDelete assertion from False to True. False was the bug.

I ran go test ./controllers/argocd/, go vet and gofmt. I did not run the E2E suite.

This overlaps with #1563 (#1559), which changes which namespace's labels the same two handlers check. I left those Get calls as they are, so whichever PR merges second will have a small conflict. I'm happy to rebase on top of #1563 if you'd rather merge that one first.

…rawn

Deleting a NamespaceManagement CR never enqueued the Argo CD instance it
named: the delete predicate returned false on every path. Retargeting
.spec.managedBy was dropped too whenever the predicate skipped or failed
its own cleanup, e.g. when the managing namespace carries a matching
managed-by label. The stale grants, such as the Image Updater manager
RBAC in the target namespace, stayed until an unrelated reconcile.

Enqueue on delete whenever the CR named an instance, and on update
whenever .spec.managedBy changes, regardless of the predicate cleanup.
The reconcile rebuilds consent and prunes what is no longer allowed.
Status-only updates are still filtered out, so the reconcile's own
status writes do not loop.

Fixes redhat-developer#1530

Signed-off-by: gabriel.carmo <admin@gabrielandre.com.br>
@openshift-ci openshift-ci Bot added the kind/bug Something isn't working label Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Withdrawing or changing namespace management consent now reliably triggers updates to access permissions, including when the managing namespace is unavailable.
    • Image Updater permissions granted through consent are removed after that consent is withdrawn. Status-only changes and deletions without a managing instance do not trigger unnecessary updates.

NamespaceManagement deletion and reassignment now enqueue the previously managing Argo CD instance, including when namespace lookup or RBAC cleanup does not complete. Tests cover event handling and RBAC removal after reconciliation.

Changes: Consent Withdrawal

Layer / File(s) Summary
Enqueue the previous managing instance
argocd-operator/controllers/argocd/util.go, argocd-operator/controllers/argocd/namespaceManagement_events_test.go, argocd-operator/controllers/argocd/util_test.go
Deletion and spec.managedBy changes enqueue reconciliation when namespace lookup fails, cleanup is skipped, or cleanup fails. Status-only updates do not enqueue. Tests cover predicate events and handler return values.
Verify RBAC removal after reconciliation
argocd-operator/controllers/argocd/namespaceManagement_events_test.go
The integration test verifies that reconciliation removes the Image Updater Role and RoleBinding after the NamespaceManagement resource is deleted.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: rizwana777

Merge Risk: Minimal · up to 42ef4

NamespaceManagement deletion and reassignment now trigger reconciliation of the previously managing Argo CD instance even when predicate cleanup is skipped or fails. This lets stale Image Updater RBAC be removed. No concrete defects were found, and the change is low risk to merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Linked issue #1530 requires: (1) deletion and reassignment of NamespaceManagement enqueue the previously affected Argo CD instance, including when predicate cleanup is skipped or fails; (2) event-path… Make the util.go diff or the handler section of util.go readable at the reviewed head, so the handleNamespaceManagementDelete and handleNamespaceManagementUpdate return values and the status-only filter can be checked against the new predic…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title states the main change: when consent is withdrawn for a NamespaceManagement CR, the named Argo CD instance is enqueued. The changeset matches this. The handlers now enqueue on delete and on …
Description check Passed The description explains the bug (the delete predicate returns false on every path, so the mapper never runs), the fix (enqueue on delete when an instance is named, and on managedBy changes regardless…
Out of Scope Changes check Passed The changed files are argocd-operator/controllers/argocd/util.go (NamespaceManagement event handlers), argocd-operator/controllers/argocd/util_test.go (one assertion flipped from false to true for the…
Full details: Title check

Explanation

The title states the main change: when consent is withdrawn for a NamespaceManagement CR, the named Argo CD instance is enqueued. The changeset matches this. The handlers now enqueue on delete and on managedBy changes, and the tests cover consent withdrawal, so the title describes the primary change.

Full details: Description check

Explanation

The description explains the bug (the delete predicate returns false on every path, so the mapper never runs), the fix (enqueue on delete when an instance is named, and on managedBy changes regardless of cleanup), and the new tests. It matches the changes in util.go, util_test.go, and namespaceManagement_events_test.go.

Full details: Out of Scope Changes check

Explanation

The changed files are argocd-operator/controllers/argocd/util.go (NamespaceManagement event handlers), argocd-operator/controllers/argocd/util_test.go (one assertion flipped from false to true for the delete handler), and the new namespaceManagement_events_test.go. All changes concern NamespaceManagement consent withdrawal and its enqueue behavior, which #1530 directly requests. The tests in the new file are supporting coverage for the same objective. No unrelated change was identified. The util.go handler diff was not readable, so this verdict covers file scope from the PR summary and the test file only.

Full details: Linked Issues check

Explanation

Linked issue #1530 requires: (1) deletion and reassignment of NamespaceManagement enqueue the previously affected Argo CD instance, including when predicate cleanup is skipped or fails; (2) event-path tests for consent withdrawal, including the matching managed-by label case; (3) tests that stale Image Updater RBAC is removed after reconcile when no valid consent remains; (4) existing cleanup behavior stays covered. The new test file namespaceManagement_events_test.go is at head and covers (2), (3), and the enqueue expectations in (1) for delete, retarget, label-match, unreadable-namespace, no-managedBy, and status-only cases. The implementation for (1) lives in the handleNamespaceManagementDelete and handleNamespaceManagementUpdate handlers in util.go. The head diff for util.go could not be read because changed blobs are missing from the checkout, and the head file read was truncated before those handlers. The handler behavior therefore rests on the PR summary and on the test expectations. Test execution was not performed, and the author reports go test ./controllers/argocd/ passed.

Resolution

Make the util.go diff or the handler section of util.go readable at the reviewed head, so the handleNamespaceManagementDelete and handleNamespaceManagementUpdate return values and the status-only filter can be checked against the new predicate tests. Confirm that go test ./controllers/argocd/ passes at head.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 54e789e and 42ef4e1.

Files selected for processing: 3

  • argocd-operator/controllers/argocd/namespaceManagement_events_test.go
  • argocd-operator/controllers/argocd/util.go
  • argocd-operator/controllers/argocd/util_test.go
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@openshift-ci

openshift-ci Bot commented Nov 27, 2026

Copy link
Copy Markdown

Hi @Gabrielandre02. Thanks for your PR.

I'm waiting for a redhat-developer 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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.

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.86%. Comparing base (54e789e) to head (42ef4e1).

Files with missing lines Patch % Lines
argocd-operator/controllers/argocd/util.go 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1613      +/-   ##
==========================================
- Coverage   70.82%   68.86%   -1.96%     
==========================================
  Files          25      118      +93     
  Lines        3873    25318   +21445     
==========================================
+ Hits         2743    17435   +14692     
- Misses       1130     7883    +6753     
Flag Coverage Δ
unit-tests 68.86% <84.61%> (-1.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

kind/bug Something isn't working needs-ok-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enqueue the previous Argo CD instance when NamespaceManagement consent is withdrawn

1 participant