fix: restoring tracking labels for cleaning up of orphaned roles and rolebindings#2017
Conversation
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
📝 WalkthroughWalkthroughAdds logic to reconcile orphaned Roles: finds Roles labeled for ArgoCD that reference Application/ApplicationSet source namespaces, verifies they are orphaned and application-scoped, and restores missing ArgoCD tracking labels on the referenced Namespaces before continuing reconciliation. Includes unit test coverage. Changes
Sequence Diagram(s)sequenceDiagram
participant Reconciler as Reconciler
participant K8sAPI as Kubernetes API
participant RoleValidator as Role Validator
participant NSMutator as Namespace Mutator
Reconciler->>K8sAPI: List Roles with ArgoCD labels
K8sAPI-->>Reconciler: Roles list
loop per Role
Reconciler->>RoleValidator: isOrphanedRole(role)
RoleValidator->>RoleValidator: check name vs App/AppSet sources
RoleValidator->>RoleValidator: hasApplicationScopedRules()
RoleValidator-->>Reconciler: valid / invalid
alt valid orphan role
Reconciler->>K8sAPI: Get referenced Namespace (skip ArgoCD namespace)
K8sAPI-->>Reconciler: Namespace
Reconciler->>RoleValidator: requiredTrackingLabelsForRole(role)
RoleValidator-->>Reconciler: labels to ensure
Reconciler->>NSMutator: addMissingLabels(namespace, labels)
NSMutator->>K8sAPI: Patch/Update Namespace
K8sAPI-->>NSMutator: Patch result
NSMutator-->>Reconciler: updated / no-op
end
end
Reconciler-->>Reconciler: Aggregate errors and continue
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@controllers/argocd/argocd_controller.go`:
- Around line 448-467: The hasApplicationScopedRules function misses wildcard
resources like "*" and therefore returns false for roles that actually grant
access; update the logic in hasApplicationScopedRules to treat a resource entry
of "*" (and optionally the group-wide wildcard) as a match: when iterating
rule.Resources inside hasApplicationScopedRules, first check if res == "*" (or
rule.Resources contains "*") and return true if so, otherwise continue the
existing switch that checks for "applications", "applications/status",
"applicationsets", "applicationsets/status"; ensure the check occurs only after
confirming the rule.APIGroups contains "argoproj.io" (const argoCDAPIGroup) so
wildcard resources in that API group are correctly recognized.
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
…ings for namespacescoped argocd instance Signed-off-by: akhil nittala <nakhil@redhat.com>
What type of PR is this?
/kind chore
What does this PR do / why we need it:
Identifies Roles and RoleBindings associated with namespace-scoped Argo CD instances and restores any missing labels to ensure correct resource tracking and cleanup.
Have you updated the necessary documentation?
Which issue(s) this PR fixes:
https://issues.redhat.com/browse/GITOPS-8537
Fixes #?
https://issues.redhat.com/browse/GITOPS-8537
How to test changes / Special notes to the reviewer:
First reproduce the issue based on the steps mentioned in the jira
Install gitops operator with changes and verify the resources which are not cleanedup as per above step.
Summary by CodeRabbit
New Features
Tests