[DMAAP] DMaaP ServiceMesh compatibility
[oom.git] / kubernetes / so / components / so-mariadb / templates / job.yaml
1 {{/*
2 # Copyright © 2017 Amdocs, Bell Canada
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16 {{- if .Values.global.migration.enabled }}
17 apiVersion: batch/v1
18 kind: Job
19 metadata:
20   name: {{ include "common.fullname" . }}-backup
21   namespace: {{ include "common.namespace" . }}
22   labels:
23     app: {{ include "common.name" . }}
24     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25     release: {{ include "common.release" . }}
26     heritage: {{ .Release.Service }}
27   annotations:
28     "helm.sh/hook": pre-upgrade,pre-install
29     "helm.sh/hook-weight": "1"
30     "helm.sh/hook-delete-policy": before-hook-creation
31 spec:
32   backoffLimit: 20
33   template:
34     metadata:
35       labels:
36         app: {{ include "common.name" . }}
37         release: {{ include "common.release" . }}
38       name: {{ include "common.name" . }}
39     spec:
40       containers:
41       - name: {{ include "common.fullname" . }}
42         image: {{ include "repositoryGenerator.image.mariadb" . }}
43         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
44         env:
45         - name: DB_HOST
46           value: {{ .Values.global.migration.dbHost }}
47         - name: DB_USER
48           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "login") | indent 10 }}
49         - name: DB_PORT
50           value: "{{ .Values.global.migration.dbPort }}"
51         - name: DB_PASS
52           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "password") | indent 10 }}
53         command:
54         - /bin/bash
55         - -c
56         - mysqldump -vv --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} --port=${DB_PORT} --databases --single-transaction --quick --lock-tables=false catalogdb requestdb nfvo > /var/data/mariadb/backup-`date +%s`.sql
57         volumeMounts:
58         - mountPath: /etc/localtime
59           name: localtime
60           readOnly: true
61         - name: backup-storage
62           mountPath: /var/data/mariadb
63       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
64       volumes:
65       - name: localtime
66         hostPath:
67           path: /etc/localtime
68       - name: backup-storage
69         persistentVolumeClaim:
70           claimName: {{ include "common.fullname" . }}-migration
71       imagePullSecrets:
72         - name: "{{ include "common.namespace" . }}-docker-registry-key"
73       restartPolicy: Never
74 ---
75 {{- end }}
76 apiVersion: batch/v1
77 kind: Job
78 metadata:
79   name: {{ include "common.fullname" . }}-config-job
80   namespace: {{ include "common.namespace" . }}
81   labels:
82     app: {{ include "common.name" . }}
83     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
84     release: {{ include "common.release" . }}
85     heritage: {{ .Release.Service }}
86   annotations:
87     "helm.sh/hook": post-upgrade,post-rollback,post-install
88     "helm.sh/hook-weight": "0"
89     "helm.sh/hook-delete-policy": before-hook-creation
90 spec:
91   backoffLimit: 20
92   template:
93     metadata:
94       labels:
95         app: {{ include "common.name" . }}-job
96         release: {{ include "common.release" . }}
97       name: {{ include "common.name" . }}
98     spec:
99       initContainers: {{ include "common.readinessCheck.waitFor" . | nindent 6 }}
100       containers:
101       - name: {{ include "common.name" . }}-config
102         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
103         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
104         command:
105         - /bin/bash
106         - -c
107         - >
108           mysql() { /usr/bin/mysql  -h ${DB_HOST} -P ${DB_PORT} "$@"; };
109           export -f mysql;
110           mysql --user=root --password=${MYSQL_ROOT_PASSWORD} requestdb -e exit > /dev/null 2>&1 {{ if not .Values.global.migration.enabled }} && echo "Database already initialized!!!" && exit 0 {{ end }};
111           for f in /docker-entrypoint-initdb.d/*; do case "$f" in  *.sh) echo "$0: running $f"; . "$f" ;;  *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;  *) echo "$0: ignoring $f" ;;  esac; echo; done;
112           {{- if .Values.global.migration.enabled }}
113           mysql -vv --user=root --password=${MYSQL_ROOT_PASSWORD} < `ls -tr /var/data/mariadb/* | tail -1`;
114           {{- end }}
115         env:
116         - name: DB_HOST
117           value: {{ include "common.mariadbService" . }}
118         - name: DB_PORT
119           value: {{ include "common.mariadbPort" . | quote }}
120         - name: MYSQL_ROOT_PASSWORD
121           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-pass" "key" "password") | indent 10 }}
122         - name: DB_USER
123           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "login") | indent 10 }}
124         - name: DB_PASSWORD
125           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "password") | indent 10 }}
126         - name: DB_ADMIN
127           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "login") | indent 10 }}
128         - name: DB_ADMIN_PASSWORD
129           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "password") | indent 10 }}
130         - name: CAMUNDA_DB_USER
131           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "login") | indent 10 }}
132         - name: CAMUNDA_DB_PASSWORD
133           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "password") | indent 10 }}
134         - name: REQUEST_DB_USER
135           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "login") | indent 10 }}
136         - name: REQUEST_DB_PASSWORD
137           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "password") | indent 10 }}
138         - name: CATALOG_DB_USER
139           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "login") | indent 10 }}
140         - name: CATALOG_DB_PASSWORD
141           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "password") | indent 10 }}
142         - name: NFVO_DB_USER
143           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "login") | indent 10 }}
144         - name: NFVO_DB_PASSWORD
145           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "password") | indent 10 }}
146         volumeMounts:
147         - mountPath: /etc/localtime
148           name: localtime
149           readOnly: true
150         - name: docker-entrypoint-initdb-d-sh
151           mountPath: "/docker-entrypoint-initdb.d"
152         - name: docker-entrypoint-initdb-d-sql
153           mountPath: "/docker-entrypoint-initdb.d/db-sql-scripts"
154         {{- if .Values.global.migration.enabled }}
155         - name: backup-storage
156           mountPath: /var/data/mariadb
157         {{- end }}
158         resources:
159 {{ include "common.resources" . | indent 12 }}
160       {{- if .Values.nodeSelector }}
161       nodeSelector:
162 {{ toYaml .Values.nodeSelector | indent 10 }}
163       {{- end -}}
164       {{- if .Values.affinity }}
165       affinity:
166 {{ toYaml .Values.affinity | indent 10 }}
167       {{- end }}
168       volumes:
169       - name: localtime
170         hostPath:
171           path: /etc/localtime
172       - name: docker-entrypoint-initdb-d-sh
173         configMap:
174           name: {{ include "common.fullname" . }}-mariadb-sh
175       - name: docker-entrypoint-initdb-d-sql
176         configMap:
177           name: {{ include "common.fullname" . }}-mariadb-sql
178       {{- if .Values.global.migration.enabled }}
179       - name: backup-storage
180         persistentVolumeClaim:
181           claimName: {{ include "common.fullname" . }}-migration
182       {{- end }}
183       restartPolicy: Never
184       imagePullSecrets:
185       - name: "{{ include "common.namespace" . }}-docker-registry-key"