[COMMON] Make imagePullSecrets configurable
[oom.git] / kubernetes / policy / templates / job.yaml
1 {{/*
2 # Copyright © 2018 Amdocs, Bell Canada
3 # Modifications Copyright © 2020 AT&T Intellectual Property
4 # Modifications Copyright (C) 2022 Nordix Foundation.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 */}}
18
19 {{ if not .Values.global.postgres.localCluster }}
20 apiVersion: batch/v1
21 kind: Job
22 metadata:
23   name: {{ include "common.fullname" . }}-galera-init
24   namespace: {{ include "common.namespace" . }}
25   labels:
26     app: {{ include "common.name" . }}-galera-init
27     release: {{ include "common.release" . }}
28 spec:
29   template:
30     metadata:
31       labels:
32         app: {{ include "common.name" . }}-galera-init
33         release: {{ include "common.release" . }}
34       name: {{ include "common.name" . }}-galera-init
35     spec:
36       {{- include "common.imagePullSecrets" . | nindent 6 }}
37       initContainers:
38       {{- if .Values.global.mariadbGalera.localCluster }}
39       {{-   if .Values.global.mariadbGalera.useOperator }}
40       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_local_operator ) | indent 6 | trim }}
41       {{    else }}
42       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_local ) | indent 6 | trim }}
43       {{-   end }}
44       {{ else }}
45       {{-   if .Values.global.mariadbGalera.useOperator }}
46       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_global_operator ) | indent 6 | trim }}
47       {{   else }}
48       {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.wait_for_global ) | indent 6 | trim }}
49       {{-   end }}
50       {{- end }}
51       containers:
52       - name: {{ include "common.name" . }}-galera-config
53         image: {{ include "repositoryGenerator.image.mariadb" . }}
54         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
55         volumeMounts:
56         - mountPath: /dbcmd-config/db.sh
57           name: {{ include "common.fullname" . }}-config
58           subPath: db.sh
59         command:
60         - /bin/sh
61         - -cx
62         - |
63            {{- if include "common.onServiceMesh" . }}
64            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
65            /dbcmd-config/db.sh
66         env:
67         - name: MYSQL_ROOT_PASSWORD
68           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-password" "key" "password") | indent 10 }}
69         - name: MYSQL_HOST
70           value: "{{ index .Values "mariadb-galera" "service" "name" }}"
71         - name: MYSQL_USER
72           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
73         - name: MYSQL_PORT
74           value: "{{ index .Values "mariadb-galera" "service" "internalPort" }}"
75         resources: {{ include "common.resources" . | nindent 10 }}
76       {{- if (include "common.onServiceMesh" .) }}
77       - name: policy-service-mesh-wait-for-job-container
78         image: {{ include "repositoryGenerator.image.quitQuit" . }}
79         imagePullPolicy: Always
80         command:
81         - /bin/sh
82         - "-c"
83         args:
84         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
85           /app/ready.py --service-mesh-check {{ include "common.name" . }}-galera-config -t 45;
86         env:
87         - name: NAMESPACE
88           valueFrom:
89             fieldRef:
90               apiVersion: v1
91               fieldPath: metadata.namespace
92       {{- end }}
93       restartPolicy: Never
94       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
95       volumes:
96         - name: {{ include "common.fullname" . }}-config
97           configMap:
98             name: {{ include "common.fullname" . }}-db-configmap
99             defaultMode: 0755
100             items:
101               - key: db.sh
102                 path: db.sh
103 {{ end }}
104
105 {{ if .Values.global.postgres.localCluster }}
106 ---
107 apiVersion: batch/v1
108 kind: Job
109 metadata:
110   name: {{ include "common.fullname" . }}-pg-init
111   namespace: {{ include "common.namespace" . }}
112   labels:
113     app: {{ include "common.name" . }}-pg-init
114     release: {{ include "common.release" . }}
115 spec:
116   template:
117     metadata:
118       labels:
119         app: {{ include "common.name" . }}-pg-init
120         release: {{ include "common.release" . }}
121       name: {{ include "common.name" . }}-pg-init
122     spec:
123       {{- include "common.imagePullSecrets" . | nindent 6 }}
124       initContainers: {{ if .Values.global.postgres.localCluster }}{{ include "common.readinessCheck.waitFor" . | nindent 6 }}{{ end }}
125       containers:
126       - name: {{ include "common.name" . }}-pg-config
127         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.postgresImage }}
128         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
129         volumeMounts:
130           - mountPath: /docker-entrypoint-initdb.d/db-pg.sh
131             name: {{ include "common.fullname" . }}-config
132             subPath: db-pg.sh
133         command:
134           - /bin/sh
135           - -cx
136           - |
137              {{- if include "common.onServiceMesh" . }}
138              echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
139              /docker-entrypoint-initdb.d/db-pg.sh
140         env:
141           - name: PG_ADMIN_PASSWORD
142             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-password" "key" "password") | indent 12 }}
143           - name: PG_HOST
144             value: "{{ .Values.postgres.service.name2 }}"
145           - name: PG_USER
146             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 12 }}
147           - name: PG_USER_PASSWORD
148             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 12 }}
149           - name: PG_PORT
150             value: "{{ .Values.postgres.service.internalPort }}"
151         resources: {{ include "common.resources" . | nindent 10 }}
152       {{- if (include "common.onServiceMesh" .) }}
153       - name: policy-service-mesh-wait-for-job-container
154         image: {{ include "repositoryGenerator.image.quitQuit" . }}
155         imagePullPolicy: Always
156         command:
157         - /bin/sh
158         - "-c"
159         args:
160         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
161           /app/ready.py --service-mesh-check {{ include "common.name" . }}-pg-config -t 45;
162         env:
163         - name: NAMESPACE
164           valueFrom:
165             fieldRef:
166               apiVersion: v1
167               fieldPath: metadata.namespace
168       {{- end }}
169       restartPolicy: Never
170       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
171       volumes:
172         - name: {{ include "common.fullname" . }}-config
173           configMap:
174             name: {{ include "common.fullname" . }}-db-configmap
175             defaultMode: 0755
176             items:
177               - key: db-pg.sh
178                 path: db-pg.sh
179 {{ end }}
180
181 ---
182 {{ if not .Values.global.postgres.localCluster }}
183 apiVersion: batch/v1
184 kind: Job
185 metadata:
186   name: {{ include "common.fullname" . }}-galera-config
187   namespace: {{ include "common.namespace" . }}
188   labels:
189     app: {{ include "common.name" . }}-galera-config
190     release: {{ include "common.release" . }}
191 spec:
192   template:
193     metadata:
194       labels:
195         app: {{ include "common.name" . }}-galera-config
196         release: {{ include "common.release" . }}
197       name: {{ include "common.name" . }}-galera-config
198     spec:
199       {{- include "common.imagePullSecrets" . | nindent 6 }}
200       initContainers:
201       - name: {{ include "common.name" . }}-init-readiness
202         image: {{ include "repositoryGenerator.image.readiness" . }}
203         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
204         command:
205         - /app/ready.py
206         args:
207         - --job-name
208         - {{ include "common.fullname" . }}-galera-init
209         env:
210         - name: NAMESPACE
211           valueFrom:
212             fieldRef:
213               apiVersion: v1
214               fieldPath: metadata.namespace
215         resources:
216           limits:
217             cpu: "100m"
218             memory: "500Mi"
219           requests:
220             cpu: "3m"
221             memory: "20Mi"
222       containers:
223       - name: {{ include "common.name" . }}-galera-db-migrator
224         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
225         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
226         volumeMounts:
227         - mountPath: /dbcmd-config/db_migrator_policy_init.sh
228           name: {{ include "common.fullname" . }}-config
229           subPath: db_migrator_policy_init.sh
230         command:
231         - /bin/sh
232         - -cx
233         - |
234            {{- if include "common.onServiceMesh" . }}
235            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
236            /dbcmd-config/db_migrator_policy_init.sh
237         env:
238         - name: SQL_HOST
239           value: "{{ index .Values "mariadb-galera" "service" "name" }}"
240         - name: SQL_USER
241           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
242         - name: SQL_PASSWORD
243           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
244         - name: SQL_DB
245           value: {{ .Values.dbmigrator.schema }}
246         - name: POLICY_HOME
247           value: {{ .Values.dbmigrator.policy_home }}
248         - name: SCRIPT_DIRECTORY
249           value: "sql"
250         resources: {{ include "common.resources" . | nindent 10 }}
251       {{- if (include "common.onServiceMesh" .) }}
252       - name: policy-service-mesh-wait-for-job-container
253         image: {{ include "repositoryGenerator.image.quitQuit" . }}
254         imagePullPolicy: Always
255         command:
256         - /bin/sh
257         - "-c"
258         args:
259         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
260           /app/ready.py --service-mesh-check {{ include "common.name" . }}-galera-db-migrator -t 45;
261         env:
262         - name: NAMESPACE
263           valueFrom:
264             fieldRef:
265               apiVersion: v1
266               fieldPath: metadata.namespace
267       {{- end }}
268       restartPolicy: Never
269       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
270       volumes:
271         - name: {{ include "common.fullname" . }}-config
272           configMap:
273             name: {{ include "common.fullname" . }}-db-configmap
274             defaultMode: 0755
275             items:
276               - key: db_migrator_policy_init.sh
277                 path: db_migrator_policy_init.sh
278 {{ end }}
279 {{ if .Values.global.postgres.localCluster }}
280 ---
281 apiVersion: batch/v1
282 kind: Job
283 metadata:
284   name: {{ include "common.fullname" . }}-pg-config
285   namespace: {{ include "common.namespace" . }}
286   labels:
287     app: {{ include "common.name" . }}-pg-config
288     release: {{ include "common.release" . }}
289 spec:
290   template:
291     metadata:
292       labels:
293         app: {{ include "common.name" . }}-pg-config
294         release: {{ include "common.release" . }}
295       name: {{ include "common.name" . }}-pg-config
296     spec:
297       {{- include "common.imagePullSecrets" . | nindent 6 }}
298       initContainers:
299       - name: {{ include "common.name" . }}-init-readiness
300         image: {{ include "repositoryGenerator.image.readiness" . }}
301         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
302         command:
303         - /app/ready.py
304         args:
305         - --job-name
306         - {{ include "common.fullname" . }}-pg-init
307         env:
308         - name: NAMESPACE
309           valueFrom:
310             fieldRef:
311               apiVersion: v1
312               fieldPath: metadata.namespace
313         resources:
314           limits:
315             cpu: "100m"
316             memory: "500Mi"
317           requests:
318             cpu: "3m"
319             memory: "20Mi"
320       containers:
321       - name: {{ include "common.name" . }}-pg-db-migrator
322         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
323         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
324         volumeMounts:
325           - mountPath: /dbcmd-config/db_migrator_pg_policy_init.sh
326             name: {{ include "common.fullname" . }}-config
327             subPath: db_migrator_pg_policy_init.sh
328         command:
329           - /bin/sh
330           - -cx
331           - |
332              {{- if include "common.onServiceMesh" . }}
333              echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
334              /dbcmd-config/db_migrator_pg_policy_init.sh
335         env:
336         - name: SQL_HOST
337           value: "{{ .Values.postgres.service.name2 }}"
338         - name: SQL_USER
339           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
340         - name: SQL_PASSWORD
341           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
342         - name: SQL_DB
343           value: {{ .Values.dbmigrator.schema }}
344         - name: POLICY_HOME
345           value: {{ .Values.dbmigrator.policy_home }}
346         - name: SCRIPT_DIRECTORY
347           value: "postgres"
348         - name: PGPASSWORD
349           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
350         resources: {{ include "common.resources" . | nindent 10 }}
351       {{- if (include "common.onServiceMesh" .) }}
352       - name: policy-service-mesh-wait-for-job-container
353         image: {{ include "repositoryGenerator.image.quitQuit" . }}
354         imagePullPolicy: Always
355         command:
356         - /bin/sh
357         - "-c"
358         args:
359         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
360           /app/ready.py --service-mesh-check {{ include "common.name" . }}-pg-db-migrator -t 45;
361         env:
362         - name: NAMESPACE
363           valueFrom:
364             fieldRef:
365               apiVersion: v1
366               fieldPath: metadata.namespace
367       {{- end }}
368       restartPolicy: Never
369       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
370       volumes:
371         - name: {{ include "common.fullname" . }}-config
372           configMap:
373             name: {{ include "common.fullname" . }}-db-configmap
374             defaultMode: 0755
375             items:
376               - key: db_migrator_pg_policy_init.sh
377                 path: db_migrator_pg_policy_init.sh
378 {{ end }}