e42757e5badf655580825b6084bacacf264c00b8
[oom.git] / kubernetes / sdnc / templates / sdnrdb-init-job.yaml
1 {{/*
2 # Copyright © 2020 highstreet technologies GmbH
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.config.sdnr.enabled -}}
17 apiVersion: batch/v1
18 kind: Job
19 metadata: {{- include "common.resourceMetadata" (dict "suffix" "sdnrdb-init-job" "dot" . ) | nindent 2 }}
20 spec:
21   backoffLimit: 20
22   template:
23     metadata: {{ include "common.templateMetadata" . | indent 6}}
24     spec:
25       initContainers:
26       - name: {{ include "common.name" . }}-readiness
27         command:
28         - /app/ready.py
29         args:
30         {{- if .Values.config.sdnr.mariadb.enabled }}
31         - --app-name
32         - {{ include "common.mariadbAppName" . }}
33         {{- else }}
34         - --container-name
35         - {{.Values.elasticsearch.nameOverride}}-elasticsearch
36         - --container-name
37         - {{.Values.elasticsearch.nameOverride}}-nginx
38         - --container-name
39         - {{.Values.elasticsearch.nameOverride}}-master
40         {{- end }}
41         env:
42         - name: NAMESPACE
43           valueFrom:
44             fieldRef:
45               apiVersion: v1
46               fieldPath: metadata.namespace
47         image: {{ include "repositoryGenerator.image.readiness" . }}
48         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
49       containers:
50       - name: {{ include "common.name" . }}-sdnrdb-init-job
51         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
52         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
53         command: ["/bin/bash"]
54         args:
55           - -c
56           - |
57             {{- if .Values.config.sdnr.mariadb.enabled }}
58             "{{ .Values.config.binDir }}/createSdnrDb.sh";
59             {{- end }}
60             sleep 90; "{{ .Values.config.binDir }}/startODL.sh"
61         env:
62           - name: SDNC_AAF_ENABLED
63             value: "false"
64           - name: SDNC_HOME
65             value: "{{.Values.config.sdncHome}}"
66           - name: ETC_DIR
67             value: "{{.Values.config.etcDir}}"
68           - name: BIN_DIR
69             value: "{{.Values.config.binDir}}"
70           ## start sdnrdb parameter
71           - name: SDNRINIT
72             value: "true"
73           {{- if .Values.config.sdnr.mariadb.enabled }}
74           - name: SDNRDBTYPE
75             value: MARIADB
76           - name: MYSQL_HOST
77             value: {{ include "common.mariadbService" . }}
78           - name: MYSQL_ROOT_PASSWORD
79             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-password" "key" "password") | indent 12 }}
80           - name: SDNRDBURL
81             value: "jdbc:mysql://{{ include "common.mariadbService" . }}:3306/{{ .Values.config.sdnr.mariadb.databaseName }}"
82           - name: SDNRDBDATABASE
83             value: "{{ .Values.config.sdnr.mariadb.databaseName }}"
84           - name: SDNRDBUSERNAME
85             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "login") | indent 12 }}
86           - name: SDNRDBPASSWORD
87             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "password") | indent 12 }}
88           {{- else }}
89           - name: SDNRDBURL
90             value: "http://{{ .Values.elasticsearch.service.name | default "sdnrdb"}}.{{.Release.Namespace}}:{{.Values.elasticsearch.service.port | default "9200"}}"
91           - name: SDNRDBPARAMETER
92             value: "-k"
93           {{- end }}
94         {{- if .Values.config.sdnr.mariadb.enabled }}
95         volumeMounts:
96           - mountPath: {{ .Values.config.binDir }}/createSdnrDb.sh
97             name: bin
98             subPath: createSdnrDb.sh
99         {{- end }}
100         resources: {{ include "common.resources" . | nindent 10 }}
101       {{- if include "common.onServiceMesh" . }}
102       - name: sdnrdb-service-mesh-wait-for-job-container
103         image: {{ include "repositoryGenerator.image.quitQuit" . }}
104         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
105         command:
106           - /bin/sh
107           - "-c"
108         args:
109           - |
110             echo "waiting 30s for istio side cars to be up"; sleep 30s;
111             /app/ready.py --service-mesh-check sdnc-sdnrdb-init-job -t 45;
112         env:
113         - name: NAMESPACE
114           valueFrom:
115             fieldRef:
116               apiVersion: v1
117               fieldPath: metadata.namespace
118       {{- end }}
119       {{- if .Values.nodeSelector }}
120       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 10 }}
121       {{- end -}}
122       {{- if .Values.affinity }}
123       affinity: {{ toYaml .Values.affinity | nindent 10 }}
124       {{- end }}
125       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
126       volumes:
127       - name: localtime
128         hostPath:
129           path: /etc/localtime
130       - name: docker-entrypoint-initdb-d
131         emptyDir: {}
132       - name: bin
133         configMap:
134           name: {{ include "common.fullname" . }}-bin
135           defaultMode: 0755
136       - name: properties
137         configMap:
138           name: {{ include "common.fullname" . }}-properties
139           defaultMode: 0644
140       restartPolicy: Never
141       imagePullSecrets:
142       - name: "{{ include "common.namespace" . }}-docker-registry-key"
143 {{ end -}}