[DCAEMOD] Uses new tpls for repos / images
[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 "common.repository" . }}/{{ .Values.image }}"
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       volumes:
64       - name: localtime
65         hostPath:
66           path: /etc/localtime
67       - name: backup-storage
68         persistentVolumeClaim:
69           claimName: {{ include "common.fullname" . }}-migration
70       imagePullSecrets:
71         - name: "{{ include "common.namespace" . }}-docker-registry-key"
72       restartPolicy: Never
73 ---
74 {{- end }}
75 apiVersion: batch/v1
76 kind: Job
77 metadata:
78   name: {{ include "common.fullname" . }}-config-job
79   namespace: {{ include "common.namespace" . }}
80   labels:
81     app: {{ include "common.name" . }}
82     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
83     release: {{ include "common.release" . }}
84     heritage: {{ .Release.Service }}
85   annotations:
86     "helm.sh/hook": post-upgrade,post-rollback,post-install
87     "helm.sh/hook-weight": "0"
88     "helm.sh/hook-delete-policy": before-hook-creation
89 spec:
90   backoffLimit: 20
91   template:
92     metadata:
93       labels:
94         app: {{ include "common.name" . }}-job
95         release: {{ include "common.release" . }}
96       name: {{ include "common.name" . }}
97     spec:
98       initContainers: {{ include "common.readinessCheck.waitFor" . | nindent 6 }}
99       containers:
100       - name: {{ include "common.name" . }}-config
101         image: "{{ include "common.repository" . }}/{{ .Values.image }}"
102         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
103         command:
104         - /bin/bash
105         - -c
106         - >
107           mysql() { /usr/bin/mysql  -h ${DB_HOST} -P ${DB_PORT} "$@"; };
108           export -f mysql;
109           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 }};
110           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;
111           {{- if .Values.global.migration.enabled }}
112           mysql -vv --user=root --password=${MYSQL_ROOT_PASSWORD} < `ls -tr /var/data/mariadb/* | tail -1`;
113           {{- end }}
114         env:
115         - name: DB_HOST
116           value: {{ include "common.mariadbService" . }}
117         - name: DB_PORT
118           value: {{ include "common.mariadbPort" . | quote }}
119         - name: MYSQL_ROOT_PASSWORD
120           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-pass" "key" "password") | indent 10 }}
121         - name: DB_USER
122           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "login") | indent 10 }}
123         - name: DB_PASSWORD
124           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "password") | indent 10 }}
125         - name: DB_ADMIN
126           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "login") | indent 10 }}
127         - name: DB_ADMIN_PASSWORD
128           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "password") | indent 10 }}
129         - name: CAMUNDA_DB_USER
130           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "login") | indent 10 }}
131         - name: CAMUNDA_DB_PASSWORD
132           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "password") | indent 10 }}
133         - name: REQUEST_DB_USER
134           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "login") | indent 10 }}
135         - name: REQUEST_DB_PASSWORD
136           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "password") | indent 10 }}
137         - name: CATALOG_DB_USER
138           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "login") | indent 10 }}
139         - name: CATALOG_DB_PASSWORD
140           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "password") | indent 10 }}
141         - name: NFVO_DB_USER
142           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "login") | indent 10 }}
143         - name: NFVO_DB_PASSWORD
144           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "password") | indent 10 }}
145         volumeMounts:
146         - mountPath: /etc/localtime
147           name: localtime
148           readOnly: true
149         - name: docker-entrypoint-initdb-d-sh
150           mountPath: "/docker-entrypoint-initdb.d"
151         - name: docker-entrypoint-initdb-d-sql
152           mountPath: "/docker-entrypoint-initdb.d/db-sql-scripts"
153         {{- if .Values.global.migration.enabled }}
154         - name: backup-storage
155           mountPath: /var/data/mariadb
156         {{- end }}
157         resources:
158 {{ include "common.resources" . | indent 12 }}
159       {{- if .Values.nodeSelector }}
160       nodeSelector:
161 {{ toYaml .Values.nodeSelector | indent 10 }}
162       {{- end -}}
163       {{- if .Values.affinity }}
164       affinity:
165 {{ toYaml .Values.affinity | indent 10 }}
166       {{- end }}
167       volumes:
168       - name: localtime
169         hostPath:
170           path: /etc/localtime
171       - name: docker-entrypoint-initdb-d-sh
172         configMap:
173           name: {{ include "common.fullname" . }}-mariadb-sh
174       - name: docker-entrypoint-initdb-d-sql
175         configMap:
176           name: {{ include "common.fullname" . }}-mariadb-sql
177       {{- if .Values.global.migration.enabled }}
178       - name: backup-storage
179         persistentVolumeClaim:
180           claimName: {{ include "common.fullname" . }}-migration
181       {{- end }}
182       restartPolicy: Never
183       imagePullSecrets:
184       - name: "{{ include "common.namespace" . }}-docker-registry-key"