[DMAAP] DMaaP ServiceMesh compatibility
[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       - name: {{ include "common.name" . }}-readiness
41         command:
42         - /app/ready.py
43         args:
44         - --container-name
45         - {{ default .Values.global.mariadbGalera.nameOverride .Values.mariadbGalera.containerName }}
46         env:
47         - name: NAMESPACE
48           valueFrom:
49             fieldRef:
50               apiVersion: v1
51               fieldPath: metadata.namespace
52         image: {{ include "repositoryGenerator.image.readiness" . }}
53         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
54       containers:
55       - name: {{ include "common.name" . }}
56         image: {{ include "repositoryGenerator.image.mariadb" . }}
57         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
58         command:
59           - /bin/sh
60           - -c
61           - |
62             /db_init/db_init.sh {{ if or .Values.dbScriptConfigMap .Values.dbScript }} &&
63             /db_config/db_cmd.sh{{ end }}
64         env:
65         - name: DB_HOST
66           value: {{ include "common.mariadbService" . }}
67         - name: DB_PORT
68           value: {{ include "common.mariadbPort" . | quote }}
69         - name: MYSQL_ROOT_PASSWORD
70           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "root-password" "key" (default "password" .Values.global.mariadbGalera.userRootSecretKey)) | indent 10 }}
71         - name: {{ printf "MYSQL_USER_%s" .Values.config.mysqlDatabase | upper }}
72           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" .Values.config.mysqlDatabase "key" "login") | indent 10 }}
73         - name: {{ printf "MYSQL_PASSWORD_%s" .Values.config.mysqlDatabase | upper }}
74           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" .Values.config.mysqlDatabase "key" "password") | indent 10 }}
75 {{- $root := . }}
76 {{ range $db, $_values := .Values.config.mysqlAdditionalDatabases }}
77         - name: {{ printf "MYSQL_USER_%s" $db | upper }}
78           {{- include "common.secret.envFromSecretFast" (dict "global" $root "uid" $db "key" "login") | indent 10 }}
79         - name: {{ printf "MYSQL_PASSWORD_%s" $db | upper }}
80           {{- include "common.secret.envFromSecretFast" (dict "global" $root "uid" $db "key" "password") | indent 10 }}
81 {{ end }}
82         volumeMounts:
83         - mountPath: /etc/localtime
84           name: localtime
85           readOnly: true
86         - name: mariadb-init
87           mountPath: /db_init/
88 {{- if or .Values.dbScriptConfigMap .Values.dbScript }}
89         - name: mariadb-conf
90           mountPath: /db_config/
91 {{- end }}
92         resources:
93 {{ include "common.resources" . | indent 12 }}
94       {{- if .Values.nodeSelector }}
95       nodeSelector:
96 {{ toYaml .Values.nodeSelector | indent 10 }}
97       {{- end -}}
98       {{- if .Values.affinity }}
99       affinity:
100 {{ toYaml .Values.affinity | indent 10 }}
101       {{- end }}
102       volumes:
103       - name: localtime
104         hostPath:
105           path: /etc/localtime
106 {{- if  or .Values.dbScriptConfigMap .Values.dbScript }}
107       - name: mariadb-conf
108         configMap:
109 {{-   if  .Values.dbScriptConfigMap }}
110           name: {{ tpl .Values.dbScriptConfigMap . }}
111 {{-   else -}}
112           name: {{ include "common.fullname" . }}-dbscript
113 {{-   end }}
114           defaultMode: 0755
115 {{- end }}
116       - name: mariadb-init
117         configMap:
118           name: {{ include "mariadbInit.configMap" . }}
119           defaultMode: 0755
120       restartPolicy: Never
121       imagePullSecrets:
122       - name: "{{ include "common.namespace" . }}-docker-registry-key"