|
67 | 67 | - user2 |
68 | 68 | ``` |
69 | 69 |
|
| 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 | + |
70 | 125 | ## Instructions |
71 | 126 |
|
72 | 127 | ### Development |
|
0 commit comments