blob: cb7fcb352a41ff463b8e795d00154047e8485d90 [file] [log] [blame]
Jakub Latusek44f0fdd2020-10-21 13:36:29 +02001{{/*
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +00002# 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.
Jakub Latusek44f0fdd2020-10-21 13:36:29 +020015*/}}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000016{{- if .Values.global.migration.enabled }}
17apiVersion: batch/v1
18kind: Job
19metadata:
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 "+" "_" }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010025 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000026 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
31spec:
32 backoffLimit: 20
33 template:
34 metadata:
35 labels:
36 app: {{ include "common.name" . }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010037 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000038 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
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +010048 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "login") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000049 - name: DB_PORT
50 value: "{{ .Values.global.migration.dbPort }}"
51 - name: DB_PASS
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +010052 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "password") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000053 command:
54 - /bin/bash
55 - -c
rope2524df55192020-08-24 13:55:58 +010056 - 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
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000057 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 }}
75apiVersion: batch/v1
76kind: Job
77metadata:
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 "+" "_" }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010083 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000084 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
89spec:
90 backoffLimit: 20
91 template:
92 metadata:
93 labels:
94 app: {{ include "common.name" . }}-job
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010095 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000096 name: {{ include "common.name" . }}
97 spec:
98 initContainers:
99 - name: {{ include "common.name" . }}-readiness
100 command:
Sylvain Desbureaux1694e1d2020-08-21 09:58:25 +0200101 - /app/ready.py
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000102 args:
103 - --container-name
104 - {{ .Values.global.mariadbGalera.nameOverride }}
105 env:
106 - name: NAMESPACE
107 valueFrom:
108 fieldRef:
109 apiVersion: v1
110 fieldPath: metadata.namespace
Sylvain Desbureaux1694e1d2020-08-21 09:58:25 +0200111 image: "{{ include "common.repository" . }}/{{ .Values.global.readinessImage }}"
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000112 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000113 containers:
114 - name: {{ include "common.name" . }}
115 image: "{{ include "common.repository" . }}/{{ .Values.image }}"
116 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
117 command:
118 - /bin/bash
119 - -c
120 - >
121 mysql() { /usr/bin/mysql -h ${DB_HOST} -P ${DB_PORT} "$@"; };
122 export -f mysql;
123 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 }};
124 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;
125 {{- if .Values.global.migration.enabled }}
126 mysql -vv --user=root --password=${MYSQL_ROOT_PASSWORD} < `ls -tr /var/data/mariadb/* | tail -1`;
127 {{- end }}
128 env:
129 - name: DB_HOST
krishnaa9692b606b2020-10-30 11:29:21 +0530130 value: {{ include "common.mariadbService" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000131 - name: DB_PORT
krishnaa9692b606b2020-10-30 11:29:21 +0530132 value: {{ include "common.mariadbPort" . | quote }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000133 - name: MYSQL_ROOT_PASSWORD
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +0100134 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-pass" "key" "password") | indent 10 }}
Krzysztof Opasiakf68b7282020-03-25 23:22:46 +0100135 - name: DB_USER
136 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "login") | indent 10 }}
137 - name: DB_PASSWORD
138 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "password") | indent 10 }}
139 - name: DB_ADMIN
140 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "login") | indent 10 }}
141 - name: DB_ADMIN_PASSWORD
142 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "password") | indent 10 }}
143 - name: CAMUNDA_DB_USER
144 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "login") | indent 10 }}
145 - name: CAMUNDA_DB_PASSWORD
146 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "password") | indent 10 }}
147 - name: REQUEST_DB_USER
148 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "login") | indent 10 }}
149 - name: REQUEST_DB_PASSWORD
150 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "password") | indent 10 }}
151 - name: CATALOG_DB_USER
152 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "login") | indent 10 }}
153 - name: CATALOG_DB_PASSWORD
154 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "password") | indent 10 }}
rope2524df55192020-08-24 13:55:58 +0100155 - name: NFVO_DB_USER
156 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "login") | indent 10 }}
157 - name: NFVO_DB_PASSWORD
158 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "password") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000159 volumeMounts:
160 - mountPath: /etc/localtime
161 name: localtime
162 readOnly: true
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200163 - name: docker-entrypoint-initdb-d-sh
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000164 mountPath: "/docker-entrypoint-initdb.d"
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200165 - name: docker-entrypoint-initdb-d-sql
166 mountPath: "/docker-entrypoint-initdb.d/db-sql-scripts"
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000167 {{- if .Values.global.migration.enabled }}
168 - name: backup-storage
169 mountPath: /var/data/mariadb
170 {{- end }}
171 resources:
172{{ include "common.resources" . | indent 12 }}
173 {{- if .Values.nodeSelector }}
174 nodeSelector:
175{{ toYaml .Values.nodeSelector | indent 10 }}
176 {{- end -}}
177 {{- if .Values.affinity }}
178 affinity:
179{{ toYaml .Values.affinity | indent 10 }}
180 {{- end }}
181 volumes:
182 - name: localtime
183 hostPath:
184 path: /etc/localtime
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200185 - name: docker-entrypoint-initdb-d-sh
186 configMap:
187 name: {{ include "common.fullname" . }}-mariadb-sh
188 - name: docker-entrypoint-initdb-d-sql
189 configMap:
190 name: {{ include "common.fullname" . }}-mariadb-sql
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000191 {{- if .Values.global.migration.enabled }}
192 - name: backup-storage
193 persistentVolumeClaim:
194 claimName: {{ include "common.fullname" . }}-migration
195 {{- end }}
196 restartPolicy: Never
197 imagePullSecrets:
198 - name: "{{ include "common.namespace" . }}-docker-registry-key"