132ac27ea23e0dcdd2883d95953714830921dd59
[oom.git] / kubernetes / common / mariadb-galera / resources / post-upgrade-script.sh
1 #!/bin/bash
2
3 TEMP_POD=$(kubectl get pod -n $NAMESPACE_ENV --selector \
4   app='{{ include "common.fullname" . }}' -o \
5   jsonpath='{.items[?(@.metadata.ownerReferences[].kind=="ReplicaSet")].metadata.name}')
6
7 tmp_MYSQL_PASSWORD=$(echo -n $(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv \
8   MYSQL_PASSWORD) | base64)
9
10 tmp_ROOT_PASSWORD=$(echo -n $(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv \
11   MYSQL_ROOT_PASSWORD) | base64)
12
13 FLAG_EX_ROOT_SEC='{{ include "common.secret.getSecretNameFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .)) }}'
14
15 FLAG_EX_SEC='{{ include "common.secret.getSecretNameFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .)) }}'
16
17 kubectl patch secret $FLAG_EX_ROOT_SEC -p \
18   '{"data":{"password":"'"$tmp_ROOT_PASSWORD"'"}}'
19
20 kubectl patch secret $FLAG_EX_SEC -p \
21   '{"data":{"password":"'"$tmp_MYSQL_PASSWORD"'"}}'
22
23 kubectl delete pod -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 --now
24 kubectl delete deployment -n $NAMESPACE_ENV {{ include "common.fullname" . }}-upgrade-deployment
25 kubectl delete secret -n $NAMESPACE_ENV {{ include "common.fullname" . }}-temp-upgrade-root
26 kubectl delete secret -n $NAMESPACE_ENV {{ include "common.fullname" . }}-temp-upgrade-usercred