-
Notifications
You must be signed in to change notification settings - Fork 7
/
sandbox-cleanup-cj.yml
57 lines (54 loc) · 1.76 KB
/
sandbox-cleanup-cj.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
apiVersion: batch/v1
kind: CronJob
metadata:
name: sandbox-cleanup
spec:
schedule: "0 12 * * 6"
successfulJobsHistoryLimit: 3 # Remove after successful completion
failedJobsHistoryLimit: 1 # Retain failed so that we see it
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
serviceAccountName: sandbox-cleanup
containers:
- name: sandbox-cleanup
image: image-registry.openshift-image-registry.svc:5000/openshift/cli
env:
- name: OBJECTS
value: all,cm,secrets,pvc
command:
- bash
- -c
- |
#!/bin/sh
get_most_api_resources() {
oc api-resources \
--verbs=list \
--namespaced \
-o name | \
grep -v "events.events.k8s.io" | \
grep -v "events" | \
grep -v "packagemanifests" | \
grep -v "operator.openshift.io" | \
grep -v "operators.coreos.com" | \
grep -v "authorization.openshift.io" | \
grep -v "serviceaccount" | \
grep -v "rbac" | \
sort | uniq
}
oc_delete_most() {
NAMESPACE=${1:-sandbox}
echo ${NAMESPACE}
sleep 3
for i in $(get_most_api_resources)
do
echo "Resource:" $i
oc -n ${NAMESPACE} \
delete ${i} \
--all
done
}
oc_delete_most sandbox