-
Notifications
You must be signed in to change notification settings - Fork 211
/
post-install-upgrade-hooks.yaml
141 lines (133 loc) · 4.65 KB
/
post-install-upgrade-hooks.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
rules:
- apiGroups:
- zookeeper.pravega.io
resources:
- "*"
verbs:
- get
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
subjects:
- kind: ServiceAccount
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{.Release.Namespace}}
roleRef:
kind: Role
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
data:
validations.sh: |
#!/bin/sh
set +e
sleep 30
echo "Checking for ready ZK replicas"
kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.conditions[?(@.type=="PodsReady")].status}' | grep True
if [ $? != 0 ]; then
echo "ZK replicas not ready"
exit 1
fi
set -e
replicasZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.replicas}'`
readyReplicasZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.readyReplicas}'`
currentVersionZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.currentVersion}'`
targetVersionZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.image.tag}'`
echo
echo "ZookeeperCluster replicas: $replicasZk"
echo "ZookeeperCluster readyReplicas: $readyReplicasZk"
echo "ZookeeperCluster currentVersion: $currentVersionZk"
echo "ZookeeperCluster targetVersion: $targetVersionZk"
echo
if [[ -z $readyReplicasZk ]]; then
echo "No ready ZK replicas"
exit 2
fi
if [[ $replicasZk != $readyReplicasZk ]]; then
echo "Wrong number of ZK replicas"
exit 3
fi
if [[ -z $currentVersionZk ]]; then
echo "Current ZK version not set"
exit 4
fi
if [[ $currentVersionZk != $targetVersionZk ]]; then
echo "Wrong current ZK version"
exit 5
fi
echo "ZookeeperCluster is ready"
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "2"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
spec:
backoffLimit: {{ .Values.hooks.backoffLimit }}
template:
metadata:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
{{- if .Values.hooks.pod.annotations }}
annotations:
{{ toYaml .Values.hooks.pod.annotations | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "zookeeper.fullname" . }}-post-install-upgrade
restartPolicy: Never
containers:
- name: post-install-upgrade-job
image: "{{ .Values.hooks.image.repository }}:{{ .Values.hooks.image.tag }}"
{{- if .Values.hooks.securityContext }}
securityContext:
{{ toYaml .Values.hooks.securityContext | indent 10 }}
{{- end }}
command:
- /scripts/validations.sh
volumeMounts:
- name: sh
mountPath: /scripts
readOnly: true
volumes:
- name: sh
configMap:
name: {{ template "zookeeper.fullname" . }}-post-install-upgrade
defaultMode: 0555