Skip to content

Commit ea9f4a0

Browse files
committed
revise: fix RBAC settings and add tests
1 parent 5a0aa65 commit ea9f4a0

File tree

8 files changed

+1833
-116
lines changed

8 files changed

+1833
-116
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,61 @@ spec:
6767
- user2
6868
```
6969

70+
### Deletion and Lifecycle Management
71+
72+
The operator implements deletion prevention to ensure safe removal of ArgoCD resources:
73+
74+
**Finalizers**: When an `ArgocdUser` is created, the operator automatically adds a finalizer (`argocd.snappcloud.io/finalizer`) to prevent accidental deletion.
75+
76+
**Deletion Protection**: An `ArgocdUser` cannot be deleted if any namespace still references it via the `argocd.snappcloud.io/appproj` label. This includes:
77+
78+
- Single-team namespaces (e.g., `argocd.snappcloud.io/appproj: team-a`)
79+
- Multi-team namespaces (e.g., `argocd.snappcloud.io/appproj: team-a.team-b`)
80+
81+
**Deletion Process**:
82+
83+
1. When you delete an `ArgocdUser`, it enters a pending deletion state
84+
2. The operator checks if any namespaces reference this team
85+
3. If namespaces still reference it, deletion is blocked and the resource remains
86+
4. Once all namespace labels are removed, the operator:
87+
- Cleans up RBAC policies from `argocd-rbac-cm`
88+
- Removes static accounts from `argocd-cm`
89+
- Deletes account passwords from `argocd-secret`
90+
- Removes the finalizer
91+
- Allows Kubernetes to complete the deletion
92+
93+
**Garbage Collection**: The operator uses OwnerReferences to enable automatic cleanup:
94+
95+
- When an `ArgocdUser` is deleted, its associated `AppProject` is automatically removed
96+
- OpenShift Groups (if used) are also automatically cleaned up
97+
- This ensures no orphaned resources remain in the cluster
98+
99+
### Architecture
100+
101+
The operator uses two separate controllers with distinct responsibilities:
102+
103+
**ArgocdUserReconciler**:
104+
105+
- Creates and manages `AppProject` resources
106+
- Configures RBAC policies and roles in `argocd-rbac-cm`
107+
- Creates static accounts in `argocd-cm`
108+
- Manages account passwords in `argocd-secret`
109+
- Creates OpenShift Groups for RBAC integration
110+
- Sets OwnerReferences for garbage collection
111+
- Manages finalizers for safe deletion
112+
113+
**NamespaceReconciler**:
114+
115+
- Watches namespace labels (`argocd.snappcloud.io/appproj` and `argocd.snappcloud.io/source`)
116+
- Updates `AppProject` destinations based on namespace labels
117+
- Updates `AppProject` source namespaces
118+
- Supports multi-team namespaces (e.g., `team-a.team-b`)
119+
- **Does not create** `AppProject` resources (only updates existing ones)
120+
121+
**Separation of Concerns**: The NamespaceReconciler only updates `AppProject` destinations and sources. It validates that the `AppProject` exists (created by ArgocdUserReconciler) before attempting updates. If an `AppProject` doesn't exist, the reconciliation fails with an error, ensuring users create the `ArgocdUser` resource first.
122+
123+
**Multi-Team Support**: When a namespace has a multi-team label (e.g., `argocd.snappcloud.io/appproj: team-a.team-b`), both teams' `AppProjects` will include that namespace in their destinations, enabling shared access.
124+
70125
## Instructions
71126

72127
### Development

config/dependency/group-crd.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: groups.user.openshift.io
5+
spec:
6+
group: user.openshift.io
7+
names:
8+
kind: Group
9+
listKind: GroupList
10+
plural: groups
11+
singular: group
12+
scope: Cluster
13+
versions:
14+
- name: v1
15+
served: true
16+
storage: true
17+
schema:
18+
openAPIV3Schema:
19+
type: object
20+
properties:
21+
apiVersion:
22+
type: string
23+
kind:
24+
type: string
25+
metadata:
26+
type: object
27+
users:
28+
type: array
29+
items:
30+
type: string

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
- /manager
2525
args:
2626
- --leader-elect
27-
image: "ghcr.io/snapp-incubator/argocd-complementary-operator:0.4.1"
27+
image: "ghcr.io/snapp-incubator/argocd-complementary-operator:0.4.2"
2828
name: manager
2929
env:
3030
- name: GODEBUG

0 commit comments

Comments
 (0)