Skip to content

Commit 84c0f79

Browse files
committed
Add ArgoCD postDelete hooks and README documentation
- Add postDelete hook components for controlplane, dataplane, and deploy-operators - Document hooks in README with usage examples and component table - Add PostDelete hooks section to ArgoCD orchestration principles README edition involved AI assistance. -- AI-Tool: Cursor AI-Agent: Composer AI-Mode: Agent Made-with: Cursor
1 parent 856a2b6 commit 84c0f79

7 files changed

Lines changed: 155 additions & 0 deletions

File tree

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ We’re using sync-waves annotations for specific jobs and actions.
6262

6363
The range -20;20 is reserved.
6464

65+
### PostDelete hooks
66+
67+
PostDelete hooks run cleanup Jobs when ArgoCD Applications are deleted (e.g., orphaned
68+
PVCs, Vault resources). See [ArgoCD postDelete hooks](#argocd-postdelete-hooks)
69+
in Consume proposed components for available components and usage.
70+
6571
### Healthchecks
6672

6773
TBD
@@ -182,6 +188,50 @@ These annotations enable ArgoCD to determine the order that resources are create
182188
# [...]
183189
```
184190

191+
### ArgoCD postDelete hooks
192+
193+
PostDelete hooks run Jobs after an ArgoCD Application is deleted. They perform
194+
cleanup that would otherwise not happen automatically when resources are removed,
195+
such as orphaned PersistentVolumeClaims, Vault-related resources, or
196+
operator-specific CRs. [Learn more about ArgoCD resource hooks](https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/).
197+
198+
**Available components**
199+
200+
| Component | Purpose |
201+
|-----------|---------|
202+
| `components/argocd/hooks/postDelete/controlplane` | Waits for pods to terminate in `openstack` namespace, then deletes PVCs, VaultStaticSecrets, VaultAuth, VaultConnection, and Secrets |
203+
| `components/argocd/hooks/postDelete/dataplane` | Deletes all `OpenStackDataPlaneService` resources before namespace cleanup |
204+
| `components/argocd/hooks/postDelete/deploy-operators` | Deletes `cluster-observability-operator` ClusterServiceVersion (CSV) resources |
205+
206+
**Example usage**
207+
208+
Include the relevant postDelete component(s) in your Application or overlay, alongside
209+
the annotations component:
210+
211+
```yaml
212+
apiVersion: argoproj.io/v1alpha1
213+
kind: Application
214+
# [...]
215+
spec:
216+
source:
217+
# [...]
218+
kustomize:
219+
components:
220+
- https://github.com/openstack-gitops/rhoso-gitops/components/argocd/annotations?ref=TAG
221+
- https://github.com/openstack-gitops/rhoso-gitops/components/argocd/hooks/postDelete/controlplane?ref=TAG
222+
```
223+
224+
From within an overlay or base kustomization:
225+
226+
```yaml
227+
apiVersion: kustomize.config.k8s.io/v1beta1
228+
kind: Kustomization
229+
components:
230+
- https://github.com/openstack-gitops/rhoso-gitops/components/argocd/annotations?ref=TAG
231+
- https://github.com/openstack-gitops/rhoso-gitops/components/argocd/hooks/postDelete/controlplane?ref=TAG
232+
# [...]
233+
```
234+
185235
## External resources
186236

187237
1. [Official RHOSO documentation](https://docs.redhat.com/en/documentation/red_hat_openstack_services_on_openshift/18.0)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: ctlplane
6+
namespace: openshift-gitops
7+
annotations:
8+
argocd.argoproj.io/hook: PostDelete
9+
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
10+
11+
spec:
12+
template:
13+
spec:
14+
serviceAccountName: openshift-gitops-argocd-application-controller
15+
restartPolicy: Never
16+
containers:
17+
- name: wait-and-clean
18+
image: registry.redhat.io/openshift4/ose-cli:latest
19+
command: ['sh', '-c']
20+
args:
21+
- |
22+
NAMESPACE="openstack"
23+
MAX_ATTEMPTS=70 # Number of retries
24+
SLEEP_SECONDS=10 # Interval (seconds) between checks
25+
attempt=1
26+
27+
while [ $attempt -le $MAX_ATTEMPTS ]; do
28+
# Count pods in the namespace
29+
pod_count=$(oc get pods -n "$NAMESPACE" --no-headers | wc -l)
30+
if [ "$pod_count" -eq 0 ]; then
31+
echo "All pods have been removed from namespace $NAMESPACE."
32+
break
33+
else
34+
echo "Attempt $attempt: $pod_count pods still present in $NAMESPACE."
35+
((attempt++))
36+
sleep "$SLEEP_SECONDS"
37+
fi
38+
done
39+
[ "$(oc get pods -n "$NAMESPACE" --no-headers | wc -l)" -eq 0 ] || exit 1
40+
oc -n openstack delete PersistentVolumeClaim --all
41+
oc -n openstack delete VaultStaticSecret --all
42+
oc -n openstack delete VaultAuth --all
43+
oc -n openstack delete VaultConnection --all
44+
oc -n openstack delete Secrets --all
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1alpha1
3+
kind: Component
4+
5+
resources:
6+
- ./controlplaneCleaning.yaml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: delete-services
6+
namespace: openshift-gitops
7+
annotations:
8+
argocd.argoproj.io/hook: PostDelete
9+
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
10+
11+
spec:
12+
template:
13+
spec:
14+
serviceAccountName: openshift-gitops-argocd-application-controller
15+
restartPolicy: Never
16+
containers:
17+
- name: dataplane-services
18+
image: registry.redhat.io/openshift4/ose-cli:latest
19+
command: ['sh', '-c']
20+
args:
21+
- |
22+
oc -n openstack delete OpenStackDataPlaneService --all
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1alpha1
3+
kind: Component
4+
5+
resources:
6+
- ./OpenStackDataPlaneService-deletion.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1alpha1
3+
kind: Component
4+
5+
resources:
6+
- ./observability-csv.yaml
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: clean-observability
6+
namespace: openshift-gitops
7+
annotations:
8+
argocd.argoproj.io/hook: PostDelete
9+
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
10+
11+
spec:
12+
template:
13+
spec:
14+
serviceAccountName: openshift-gitops-argocd-application-controller
15+
restartPolicy: Never
16+
containers:
17+
- name: clean-observability-csv
18+
image: registry.redhat.io/openshift4/ose-cli:latest
19+
command: ['sh', '-c']
20+
args:
21+
- oc get csv -A | awk '/cluster-observability-operator/ {print $1, $2}' | sort -u | xargs -n2 sh -c 'oc -n $0 delete csv $1'

0 commit comments

Comments
 (0)