-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-upgrade.yaml
96 lines (96 loc) · 2.85 KB
/
pre-upgrade.yaml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
apiVersion: v1
kind: ServiceAccount
metadata:
name: namespaceconfig-preupgrade
namespace: namespace-configuration-operator
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: namespaceconfig-preupgrade
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- apiGroups:
- redhatcop.redhat.io
resources:
- namespaceconfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- redhatcop.redhat.io
resources:
- namespaceconfigs/finalizers
verbs:
- update
- patch
- apiGroups:
- redhatcop.redhat.io
resources:
- namespaceconfigs/status
verbs:
- get
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: namespaceconfig-preupgrade
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: namespaceconfig-preupgrade
subjects:
- name: namespaceconfig-preupgrade
namespace: namespace-configuration-operator
kind: ServiceAccount
---
apiVersion: batch/v1
kind: Job
metadata:
name: namespaceconfig-preupgrade
namespace: namespace-configuration-operator
spec:
template:
metadata:
name: namespaceconfig-preupgrade
spec:
restartPolicy: Never
serviceAccountName: namespaceconfig-preupgrade
containers:
- name: preupgrade
image: "bitnami/kubectl:latest"
command: ["/bin/bash"]
args:
- -c
- |
set -x # print each line as evaluated
NSCONFIG_OBJECTS=$(kubectl get namespaceconfig -o jsonpath='{.items[*].metadata.name}')
test -z "$NSCONFIG_OBJECTS" && echo "No namespaceconfig objects found..." && exit 0
echo "Checking the Finalizer value and deletiontimestamp in the objects."
for NSCO in $NSCONFIG_OBJECTS; do
FINIALIZER_NAME=$(kubectl get namespaceconfig $NSCO -o jsonpath='{.metadata.finalizers[0]}')
DELETION_TIMESTAMP=$(kubectl get namespaceconfig $NSCO -o jsonpath='{.metadata.deletionTimestamp}')
if [ "$FINIALIZER_NAME" == "namespace-config-operator" -a "$DELETION_TIMESTAMP" != "" ]; then
echo "Found old Finializer in the NamespaceConfig object and also marked for deletion. \n
Making the Finalizers list to empty to get the object deleted."
kubectl patch --type=merge namespaceconfig $NSCO -p '{"metadata": {"finalizers": null}}'
fi
done
while true; do
NAMESPACECONFIG_CRD=$(kubectl get crd namespaceconfigs.redhatcop.redhat.io --ignore-not-found=true -o jsonpath='{.metadata.name}')
test -z "$NAMESPACECONFIG_CRD" && echo "namespaceconfigs CRD is deleted..." && exit 0
echo "Waiting for the namespaceconfigs crd to be deleted. Sleeping 10 seconds."
sleep 10
done