419a9c4109e6aca5812efa9ea4435cce957728cf
[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         - --service-name
32         - {{ include "common.mariadbService" . }}
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         resources:
50           limits:
51             cpu: "100m"
52             memory: "500Mi"
53           requests:
54             cpu: "3m"
55             memory: "20Mi"
56       containers:
57       - name: {{ include "common.name" . }}-sdnrdb-init-job
58         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
59         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
60         command: ["/bin/bash"]
61         args:
62           - -c
63           - |
64             {{- if .Values.config.sdnr.mariadb.enabled }}
65             "{{ .Values.config.binDir }}/createSdnrDb.sh";
66             {{- end }}
67             sleep 90; "{{ .Values.config.binDir }}/startODL.sh"
68         env:
69           - name: SDNC_AAF_ENABLED
70             value: "false"
71           - name: SDNC_HOME
72             value: "{{.Values.config.sdncHome}}"
73           - name: ETC_DIR
74             value: "{{.Values.config.etcDir}}"
75           - name: BIN_DIR
76             value: "{{.Values.config.binDir}}"
77           ## start sdnrdb parameter
78           - name: SDNRINIT
79             value: "true"
80           {{- if .Values.config.sdnr.mariadb.enabled }}
81           - name: SDNRDBTYPE
82             value: MARIADB
83           - name: MYSQL_HOST
84             value: {{ include "common.mariadbService" . }}
85           - name: MYSQL_ROOT_PASSWORD
86             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-password" "key" "password") | indent 12 }}
87           - name: SDNRDBURL
88             value: "jdbc:mysql://{{ include "common.mariadbService" . }}:3306/{{ .Values.config.sdnr.mariadb.databaseName }}"
89           - name: SDNRDBDATABASE
90             value: "{{ .Values.config.sdnr.mariadb.databaseName }}"
91           - name: SDNRDBUSERNAME
92             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "login") | indent 12 }}
93           - name: SDNRDBPASSWORD
94             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "password") | indent 12 }}
95           {{- else }}
96           - name: SDNRDBURL
97             value: "http://{{ .Values.elasticsearch.service.name | default "sdnrdb"}}.{{.Release.Namespace}}:{{.Values.elasticsearch.service.port | default "9200"}}"
98           - name: SDNRDBPARAMETER
99             value: "-k"
100           {{- end }}
101         {{- if .Values.config.sdnr.mariadb.enabled }}
102         volumeMounts:
103           - mountPath: {{ .Values.config.binDir }}/createSdnrDb.sh
104             name: bin
105             subPath: createSdnrDb.sh
106         {{- end }}
107         resources: {{ include "common.resources" . | nindent 10 }}
108       {{- if include "common.onServiceMesh" . }}
109       - name: sdnrdb-service-mesh-wait-for-job-container
110         image: {{ include "repositoryGenerator.image.quitQuit" . }}
111         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
112         command:
113           - /bin/sh
114           - "-c"
115         args:
116           - |
117             echo "waiting 30s for istio side cars to be up"; sleep 30s;
118             /app/ready.py --service-mesh-check sdnc-sdnrdb-init-job -t 45;
119         env:
120         - name: NAMESPACE
121           valueFrom:
122             fieldRef:
123               apiVersion: v1
124               fieldPath: metadata.namespace
125       {{- end }}
126       {{- if .Values.nodeSelector }}
127       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 10 }}
128       {{- end -}}
129       {{- if .Values.affinity }}
130       affinity: {{ toYaml .Values.affinity | nindent 10 }}
131       {{- end }}
132       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
133       volumes:
134       - name: localtime
135         hostPath:
136           path: /etc/localtime
137       - name: docker-entrypoint-initdb-d
138         emptyDir: {}
139       - name: bin
140         configMap:
141           name: {{ include "common.fullname" . }}-bin
142           defaultMode: 0755
143       - name: properties
144         configMap:
145           name: {{ include "common.fullname" . }}-properties
146           defaultMode: 0644
147       restartPolicy: Never
148       {{- include "common.imagePullSecrets" . | nindent 6 }}
149 {{ end -}}