1+ {{- if .Values.webhooks.conversionEnabled }}
2+ apiVersion : batch/v1
3+ kind : Job
4+ metadata :
5+ name : {{ .Release.Name }}-crd-patch
6+ namespace : {{ .Release.Namespace }}
7+ labels :
8+ {{- include "kubeblocks.labels" . | nindent 4 }}
9+ annotations :
10+ " helm.sh/hook " : post-install
11+ " helm.sh/hook-delete-policy " : " before-hook-creation,hook-succeeded"
12+ spec :
13+ ttlSecondsAfterFinished : 0
14+ backoffLimit : 2
15+ template :
16+ metadata :
17+ name : {{ .Release.Name }}-crd-patch
18+ labels :
19+ {{- include "kubeblocks.labels" . | nindent 8 }}
20+ spec :
21+ {{- with .Values.image.imagePullSecrets }}
22+ imagePullSecrets :
23+ {{- toYaml . | nindent 8 }}
24+ {{- end }}
25+ serviceAccountName : {{ include "kubeblocks.serviceAccountName" . }}
26+ securityContext :
27+ {{- toYaml .Values.podSecurityContext | nindent 8 }}
28+ restartPolicy : Never
29+ containers :
30+ - name : post-install-job
31+ image : " {{ .Values.image.registry | default " docker.io" }}/{{ .Values.image.tools.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
32+ imagePullPolicy : {{ .Values.image.pullPolicy }}
33+ command :
34+ - sh
35+ - -c
36+ - |
37+ set -e
38+ # 1. check the already installed KubeBlocks
39+ deployments=$(kubectl get deployments -A -l app.kubernetes.io/name=kubeblocks --no-headers)
40+ OLD_IFS=$IFS
41+ IFS=$'\n'
42+ for line in $deployments; do
43+ namespace=$(echo "$line" | awk '{print $1}')
44+ name=$(echo "$line" | awk '{print $2}')
45+ old_kb_json=$(kubectl get deployment ${name} -n ${namespace} -o json)
46+ version=$(echo ${old_kb_json} | jq '.metadata.labels["app.kubernetes.io/version"]' | tr -d '"')
47+ replicas=$(echo ${old_kb_json} | jq '.spec.replicas')
48+ statusReplicas=$(echo ${old_kb_json} | jq '.status.replicas')
49+ if echo "$version" | grep -q '^0\.9'; then
50+ echo "TODO: add it when released 0.9.2"
51+ # patch_num=$(echo $version | awk -F. '{print $3}' | awk -F- '{print $1}')
52+ # if [ "$version" != "0.9.2" ] && [ $patch_num -le 2 ]; then
53+ # echo "ERROR: the installed KubeBlocks version must greater and equal to 0.9.2"
54+ # exit 1
55+ # fi
56+ elif echo "$version" | grep -q '^0\.'; then
57+ echo "ERROR: can not upgrade KubeBlocks from $version to {{ .Chart.AppVersion }}"
58+ exit 1
59+ fi
60+ if [ $replicas -ne 0 ]; then
61+ echo "ERROR: You must stop the existing ${namespace}/${name} version (${version}) before installing version 1.0."
62+ exit 1
63+ fi
64+ echo "status: $statusReplicas"
65+ if [ "$statusReplicas" != "null" ] || [ $statusReplicas -ne 0 ]; then
66+ echo "ERROR: You must stop the existing ${namespace}/${name} version (${version}) before installing version 1.0."
67+ exit 1
68+ fi
69+ done
70+ IFS=$OLD_IFS
71+ # 2. patch crds
72+ patch_crd_cmd="kubectl patch crd --patch-file=/opt/conversion_webhook_patch.json"
73+ ${patch_crd_cmd} "clusterdefinitions.apps.kubeblocks.io"
74+ ${patch_crd_cmd} "clusters.apps.kubeblocks.io"
75+ ${patch_crd_cmd} "componentdefinitions.apps.kubeblocks.io"
76+ ${patch_crd_cmd} "components.apps.kubeblocks.io"
77+ ${patch_crd_cmd} "componentversions.apps.kubeblocks.io"
78+ ${patch_crd_cmd} "instancesets.workloads.kubeblocks.io"
79+ ${patch_crd_cmd} "servicedescriptors.apps.kubeblocks.io"
80+
81+ # 3. start KubeBlocks
82+ kubectl patch deployment {{ include "kubeblocks.fullname" . }} -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
83+ {{- if .Values.dataProtection.enabled }}
84+ kubectl patch deployment {{ include "kubeblocks.fullname" . }}-dataprotection -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
85+ {{- end }}
86+ volumeMounts :
87+ - mountPath : /opt
88+ name : crd-multi-version-conversion
89+ {{- with .Values.topologySpreadConstraints }}
90+ topologySpreadConstraints :
91+ {{- toYaml . | nindent 8 }}
92+ {{- end }}
93+ {{- with .Values.affinity }}
94+ affinity :
95+ {{- toYaml . | nindent 8 }}
96+ {{- end }}
97+ {{- with .Values.nodeSelector }}
98+ nodeSelector :
99+ {{- toYaml . | nindent 8 }}
100+ {{- end }}
101+ {{- with .Values.tolerations }}
102+ tolerations :
103+ {{- toYaml . | nindent 8 }}
104+ {{- end }}
105+ volumes :
106+ - name : crd-multi-version-conversion
107+ configMap :
108+ name : {{ include "kubeblocks.fullname" . }}.{{ .Release.Namespace }}.crd.conversion.webhook
109+ {{- end }}
0 commit comments