[COMMON] Make imagePullSecrets configurable
[oom.git] / kubernetes / common / mariadb-init / templates / job.yaml
1 {{/*
2 # Copyright © 2019 Orange
3 # Copyright © 2020 Samsung Electronics
4 #
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.
16 */}}
17
18 {{ include "mariadbInit._updateSecrets" . -}}
19
20 apiVersion: batch/v1
21 kind: Job
22 metadata:
23   name: {{ include "common.fullname" . }}-config-job
24   namespace: {{ include "common.namespace" . }}
25   labels:
26     app: {{ include "common.name" . }}
27     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
28     release: {{ include "common.release" . }}
29     heritage: {{ .Release.Service }}
30 spec:
31   backoffLimit: 20
32   template:
33     metadata:
34       labels:
35         app: {{ include "common.name" . }}
36         release: {{ include "common.release" . }}
37       name: {{ include "common.name" . }}
38     spec:
39       initContainers:
40       {{- if .Values.global.mariadbGalera.localCluster }}
41       {{-   if .Values.global.mariadbGalera.useOperator }}
42       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_local_operator ) | indent 6 | trim }}
43       {{    else }}
44       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_local ) | indent 6 | trim }}
45       {{-   end }}
46       {{ else }}
47       {{-   if .Values.global.mariadbGalera.useOperator }}
48       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_global_operator ) | indent 6 | trim }}
49       {{   else }}
50       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_global ) | indent 6 | trim }}
51       {{-   end }}
52       {{- end }}
53       containers:
54       - name: {{ include "common.name" . }}
55         image: {{ include "repositoryGenerator.image.mariadb" . }}
56         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
57         command:
58           - /bin/sh
59           - -c
60           - |
61             {{- if include "common.onServiceMesh" . }}
62             echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
63             /db_init/db_init.sh {{ if or .Values.dbScriptConfigMap .Values.dbScript }} &&
64             /db_config/db_cmd.sh{{ end }}
65         env:
66         - name: DB_HOST
67           value: {{ include "common.mariadbService" . }}
68         - name: DB_PORT
69           value: {{ include "common.mariadbPort" . | quote }}
70         - name: MYSQL_ROOT_PASSWORD
71           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "root-password" "key" (default "password" .Values.global.mariadbGalera.userRootSecretKey)) | indent 10 }}
72         - name: {{ printf "MYSQL_USER_%s" .Values.config.mysqlDatabase | upper }}
73           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" .Values.config.mysqlDatabase "key" "login") | indent 10 }}
74         - name: {{ printf "MYSQL_PASSWORD_%s" .Values.config.mysqlDatabase | upper }}
75           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" .Values.config.mysqlDatabase "key" "password") | indent 10 }}
76 {{- $root := . }}
77 {{ range $db, $_values := .Values.config.mysqlAdditionalDatabases }}
78         - name: {{ printf "MYSQL_USER_%s" $db | upper }}
79           {{- include "common.secret.envFromSecretFast" (dict "global" $root "uid" $db "key" "login") | indent 10 }}
80         - name: {{ printf "MYSQL_PASSWORD_%s" $db | upper }}
81           {{- include "common.secret.envFromSecretFast" (dict "global" $root "uid" $db "key" "password") | indent 10 }}
82 {{ end }}
83         volumeMounts:
84         - mountPath: /etc/localtime
85           name: localtime
86           readOnly: true
87         - name: mariadb-init
88           mountPath: /db_init/
89 {{- if or .Values.dbScriptConfigMap .Values.dbScript }}
90         - name: mariadb-conf
91           mountPath: /db_config/
92 {{- end }}
93         resources: {{ include "common.resources" . | nindent 10 }}
94       {{ include "common.waitForJobContainer" . | indent 6 | trim }}
95       {{- if .Values.nodeSelector }}
96       nodeSelector:
97 {{ toYaml .Values.nodeSelector | indent 10 }}
98       {{- end -}}
99       {{- if .Values.affinity }}
100       affinity:
101 {{ toYaml .Values.affinity | indent 10 }}
102       {{- end }}
103       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
104       volumes:
105       - name: localtime
106         hostPath:
107           path: /etc/localtime
108 {{- if  or .Values.dbScriptConfigMap .Values.dbScript }}
109       - name: mariadb-conf
110         configMap:
111 {{-   if  .Values.dbScriptConfigMap }}
112           name: {{ tpl .Values.dbScriptConfigMap . }}
113 {{-   else -}}
114           name: {{ include "common.fullname" . }}-dbscript
115 {{-   end }}
116           defaultMode: 0755
117 {{- end }}
118       - name: mariadb-init
119         configMap:
120           name: {{ include "mariadbInit.configMap" . }}
121           defaultMode: 0755
122       restartPolicy: Never
123       {{- include "common.imagePullSecrets" . | nindent 6 }}