blob: abbe5997ee0c9681a51513a2b80d0c68ba90687b [file] [log] [blame]
Jakub Latusek44f0fdd2020-10-21 13:36:29 +02001{{/*
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +00002# Copyright © 2017 Amdocs, Bell Canada
egernugf4004322022-06-08 10:33:44 +01003# Modifications Copyright (C) 2022/23 Nordix Foundation
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Jakub Latusek44f0fdd2020-10-21 13:36:29 +020016*/}}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000017{{- if .Values.global.migration.enabled }}
18apiVersion: batch/v1
19kind: Job
20metadata:
21 name: {{ include "common.fullname" . }}-backup
22 namespace: {{ include "common.namespace" . }}
23 labels:
24 app: {{ include "common.name" . }}
25 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010026 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000027 heritage: {{ .Release.Service }}
28 annotations:
29 "helm.sh/hook": pre-upgrade,pre-install
30 "helm.sh/hook-weight": "1"
31 "helm.sh/hook-delete-policy": before-hook-creation
32spec:
33 backoffLimit: 20
34 template:
35 metadata:
36 labels:
37 app: {{ include "common.name" . }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010038 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000039 name: {{ include "common.name" . }}
40 spec:
41 containers:
42 - name: {{ include "common.fullname" . }}
Sylvain Desbureaux0d2cf1a2022-01-05 16:08:27 +010043 image: {{ include "repositoryGenerator.image.mariadb" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000044 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
45 env:
46 - name: DB_HOST
47 value: {{ .Values.global.migration.dbHost }}
48 - name: DB_USER
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +010049 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "login") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000050 - name: DB_PORT
51 value: "{{ .Values.global.migration.dbPort }}"
52 - name: DB_PASS
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +010053 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "password") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000054 command:
55 - /bin/bash
56 - -c
Andreas Geissler17be9622022-04-29 13:33:02 +020057 - |
58 {{- if include "common.onServiceMesh" . }}
59 echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
egernugf4004322022-06-08 10:33:44 +010060 mysqldump -vv --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} --port=${DB_PORT} --databases --single-transaction --quick --lock-tables=false catalogdb requestdb nfvo cnfm > /var/data/mariadb/backup-`date +%s`.sql
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000061 volumeMounts:
62 - mountPath: /etc/localtime
63 name: localtime
64 readOnly: true
65 - name: backup-storage
66 mountPath: /var/data/mariadb
Andreas Geissler17be9622022-04-29 13:33:02 +020067 {{ include "common.waitForJobContainer" . | indent 6 | trim }}
farida azmy87f46222021-04-06 15:25:15 +020068 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000069 volumes:
70 - name: localtime
71 hostPath:
72 path: /etc/localtime
73 - name: backup-storage
74 persistentVolumeClaim:
75 claimName: {{ include "common.fullname" . }}-migration
76 imagePullSecrets:
77 - name: "{{ include "common.namespace" . }}-docker-registry-key"
78 restartPolicy: Never
79---
80{{- end }}
81apiVersion: batch/v1
82kind: Job
83metadata:
84 name: {{ include "common.fullname" . }}-config-job
85 namespace: {{ include "common.namespace" . }}
86 labels:
87 app: {{ include "common.name" . }}
88 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010089 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +000090 heritage: {{ .Release.Service }}
91 annotations:
92 "helm.sh/hook": post-upgrade,post-rollback,post-install
93 "helm.sh/hook-weight": "0"
94 "helm.sh/hook-delete-policy": before-hook-creation
95spec:
96 backoffLimit: 20
97 template:
98 metadata:
99 labels:
100 app: {{ include "common.name" . }}-job
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +0100101 release: {{ include "common.release" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000102 name: {{ include "common.name" . }}
103 spec:
Andreas Geissler2c1ba292024-01-10 22:20:05 +0100104 initContainers:
105 - name: {{ include "common.name" . }}-readiness
106 command:
107 - /app/ready.py
108 args:
109 - --app-name
110 - {{ include "common.mariadbAppName" . }}
111 env:
112 - name: NAMESPACE
113 valueFrom:
114 fieldRef:
115 apiVersion: v1
116 fieldPath: metadata.namespace
117 image: {{ include "repositoryGenerator.image.readiness" . }}
118 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
Andreas Geissler47537432024-02-27 08:55:23 +0100119 resources:
120 limits:
121 cpu: "100m"
122 memory: "0.5Gi"
123 requests:
124 cpu: "3m"
125 memory: "0.02Gi"
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000126 containers:
Sylvain Desbureauxd055a172020-10-30 14:32:03 +0100127 - name: {{ include "common.name" . }}-config
Sylvain Desbureaux747982c2020-11-19 17:40:05 +0100128 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000129 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
130 command:
131 - /bin/bash
132 - -c
133 - >
Andreas Geissler17be9622022-04-29 13:33:02 +0200134 {{- if include "common.onServiceMesh" . }}
135 echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000136 mysql() { /usr/bin/mysql -h ${DB_HOST} -P ${DB_PORT} "$@"; };
137 export -f mysql;
138 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 }};
139 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;
140 {{- if .Values.global.migration.enabled }}
141 mysql -vv --user=root --password=${MYSQL_ROOT_PASSWORD} < `ls -tr /var/data/mariadb/* | tail -1`;
142 {{- end }}
143 env:
144 - name: DB_HOST
krishnaa9692b606b2020-10-30 11:29:21 +0530145 value: {{ include "common.mariadbService" . }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000146 - name: DB_PORT
krishnaa9692b606b2020-10-30 11:29:21 +0530147 value: {{ include "common.mariadbPort" . | quote }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000148 - name: MYSQL_ROOT_PASSWORD
Krzysztof Opasiak587b6e62020-03-24 03:26:03 +0100149 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-pass" "key" "password") | indent 10 }}
Krzysztof Opasiakf68b7282020-03-25 23:22:46 +0100150 - name: DB_USER
151 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "login") | indent 10 }}
152 - name: DB_PASSWORD
153 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "password") | indent 10 }}
154 - name: DB_ADMIN
155 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "login") | indent 10 }}
156 - name: DB_ADMIN_PASSWORD
157 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "password") | indent 10 }}
158 - name: CAMUNDA_DB_USER
159 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "login") | indent 10 }}
160 - name: CAMUNDA_DB_PASSWORD
161 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "password") | indent 10 }}
162 - name: REQUEST_DB_USER
163 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "login") | indent 10 }}
164 - name: REQUEST_DB_PASSWORD
165 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "password") | indent 10 }}
166 - name: CATALOG_DB_USER
167 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "login") | indent 10 }}
168 - name: CATALOG_DB_PASSWORD
169 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "password") | indent 10 }}
rope2524df55192020-08-24 13:55:58 +0100170 - name: NFVO_DB_USER
171 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "login") | indent 10 }}
172 - name: NFVO_DB_PASSWORD
173 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "nfvo-db-creds" "key" "password") | indent 10 }}
egernugf4004322022-06-08 10:33:44 +0100174 - name: CNFM_DB_USER
175 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "cnfm-db-creds" "key" "login") | indent 10 }}
176 - name: CNFM_DB_PASSWORD
177 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "cnfm-db-creds" "key" "password") | indent 10 }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000178 volumeMounts:
179 - mountPath: /etc/localtime
180 name: localtime
181 readOnly: true
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200182 - name: docker-entrypoint-initdb-d-sh
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000183 mountPath: "/docker-entrypoint-initdb.d"
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200184 - name: docker-entrypoint-initdb-d-sql
185 mountPath: "/docker-entrypoint-initdb.d/db-sql-scripts"
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000186 {{- if .Values.global.migration.enabled }}
187 - name: backup-storage
188 mountPath: /var/data/mariadb
189 {{- end }}
miroslavmasaryka7ac7f02023-03-01 14:12:26 +0100190 resources: {{ include "common.resources" . | nindent 10 }}
Andreas Geissler17be9622022-04-29 13:33:02 +0200191 {{ include "common.waitForJobContainer" . | indent 6 | trim }}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000192 {{- if .Values.nodeSelector }}
193 nodeSelector:
194{{ toYaml .Values.nodeSelector | indent 10 }}
195 {{- end -}}
196 {{- if .Values.affinity }}
197 affinity:
198{{ toYaml .Values.affinity | indent 10 }}
199 {{- end }}
vladimir turokd8044182023-07-27 16:28:36 +0200200 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000201 volumes:
202 - name: localtime
203 hostPath:
204 path: /etc/localtime
Tomáš Levora2a63ef32019-09-20 08:16:54 +0200205 - name: docker-entrypoint-initdb-d-sh
206 configMap:
207 name: {{ include "common.fullname" . }}-mariadb-sh
208 - name: docker-entrypoint-initdb-d-sql
209 configMap:
210 name: {{ include "common.fullname" . }}-mariadb-sql
Mahendra Raghuwanshi72b69c12019-04-04 10:43:25 +0000211 {{- if .Values.global.migration.enabled }}
212 - name: backup-storage
213 persistentVolumeClaim:
214 claimName: {{ include "common.fullname" . }}-migration
215 {{- end }}
216 restartPolicy: Never
217 imagePullSecrets:
218 - name: "{{ include "common.namespace" . }}-docker-registry-key"