[COMMON] Fix resources indent
[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 apiVersion: batch/v1
20 kind: Job
21 metadata:
22   name: {{ include "common.fullname" . }}-galera-init
23   namespace: {{ include "common.namespace" . }}
24   labels:
25     app: {{ include "common.name" . }}-galera-init
26     release: {{ include "common.release" . }}
27 spec:
28   template:
29     metadata:
30       labels:
31         app: {{ include "common.name" . }}-galera-init
32         release: {{ include "common.release" . }}
33       name: {{ include "common.name" . }}-galera-init
34     spec:
35       imagePullSecrets:
36       - name: "{{ include "common.namespace" . }}-docker-registry-key"
37       initContainers:
38       - name: {{ include "common.name" . }}-mariadb-readiness
39         image: {{ include "repositoryGenerator.image.readiness" . }}
40         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
41         command:
42         - /app/ready.py
43         - --container-name
44         - {{ index .Values "mariadb-galera" "service" "name" }}
45         env:
46         - name: NAMESPACE
47           valueFrom:
48             fieldRef:
49               apiVersion: v1
50               fieldPath: metadata.namespace
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
104 {{ if .Values.global.postgres.localCluster }}
105 ---
106 apiVersion: batch/v1
107 kind: Job
108 metadata:
109   name: {{ include "common.fullname" . }}-pg-init
110   namespace: {{ include "common.namespace" . }}
111   labels:
112     app: {{ include "common.name" . }}-pg-init
113     release: {{ include "common.release" . }}
114 spec:
115   template:
116     metadata:
117       labels:
118         app: {{ include "common.name" . }}-pg-init
119         release: {{ include "common.release" . }}
120       name: {{ include "common.name" . }}-pg-init
121     spec:
122       imagePullSecrets:
123       - name: "{{ include "common.namespace" . }}-docker-registry-key"
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" "pg-root-pass" "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" "pg-user-creds" "key" "login") | indent 12 }}
147           - name: PG_USER_PASSWORD
148             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "pg-user-creds" "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 apiVersion: batch/v1
183 kind: Job
184 metadata:
185   name: {{ include "common.fullname" . }}-galera-config
186   namespace: {{ include "common.namespace" . }}
187   labels:
188     app: {{ include "common.name" . }}-galera-config
189     release: {{ include "common.release" . }}
190 spec:
191   template:
192     metadata:
193       labels:
194         app: {{ include "common.name" . }}-galera-config
195         release: {{ include "common.release" . }}
196       name: {{ include "common.name" . }}-galera-config
197     spec:
198       imagePullSecrets:
199       - name: "{{ include "common.namespace" . }}-docker-registry-key"
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       containers:
216       - name: {{ include "common.name" . }}-galera-db-migrator
217         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
218         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
219         volumeMounts:
220         - mountPath: /dbcmd-config/db_migrator_policy_init.sh
221           name: {{ include "common.fullname" . }}-config
222           subPath: db_migrator_policy_init.sh
223         command:
224         - /bin/sh
225         - -cx
226         - |
227            {{- if include "common.onServiceMesh" . }}
228            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
229            /dbcmd-config/db_migrator_policy_init.sh
230         env:
231         - name: SQL_HOST
232           value: "{{ index .Values "mariadb-galera" "service" "name" }}"
233         - name: SQL_USER
234           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
235         - name: SQL_PASSWORD
236           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
237         - name: SQL_DB
238           value: {{ .Values.dbmigrator.schema }}
239         - name: POLICY_HOME
240           value: {{ .Values.dbmigrator.policy_home }}
241         - name: SCRIPT_DIRECTORY
242           value: "sql"
243         resources: {{ include "common.resources" . | nindent 10 }}
244       {{- if (include "common.onServiceMesh" .) }}
245       - name: policy-service-mesh-wait-for-job-container
246         image: {{ include "repositoryGenerator.image.quitQuit" . }}
247         imagePullPolicy: Always
248         command:
249         - /bin/sh
250         - "-c"
251         args:
252         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
253           /app/ready.py --service-mesh-check {{ include "common.name" . }}-galera-db-migrator -t 45;
254         env:
255         - name: NAMESPACE
256           valueFrom:
257             fieldRef:
258               apiVersion: v1
259               fieldPath: metadata.namespace
260       {{- end }}
261       restartPolicy: Never
262       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
263       volumes:
264         - name: {{ include "common.fullname" . }}-config
265           configMap:
266             name: {{ include "common.fullname" . }}-db-configmap
267             defaultMode: 0755
268             items:
269               - key: db_migrator_policy_init.sh
270                 path: db_migrator_policy_init.sh
271
272 {{ if .Values.global.postgres.localCluster }}
273 ---
274 apiVersion: batch/v1
275 kind: Job
276 metadata:
277   name: {{ include "common.fullname" . }}-pg-config
278   namespace: {{ include "common.namespace" . }}
279   labels:
280     app: {{ include "common.name" . }}-pg-config
281     release: {{ include "common.release" . }}
282 spec:
283   template:
284     metadata:
285       labels:
286         app: {{ include "common.name" . }}-pg-config
287         release: {{ include "common.release" . }}
288       name: {{ include "common.name" . }}-pg-config
289     spec:
290       imagePullSecrets:
291       - name: "{{ include "common.namespace" . }}-docker-registry-key"
292       initContainers:
293         - name: {{ include "common.name" . }}-init-readiness
294           image: {{ include "repositoryGenerator.image.readiness" . }}
295           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
296           command:
297           - /app/ready.py
298           args:
299           - --job-name
300           - {{ include "common.fullname" . }}-pg-init
301           env:
302           - name: NAMESPACE
303             valueFrom:
304               fieldRef:
305                 apiVersion: v1
306                 fieldPath: metadata.namespace
307       containers:
308       - name: {{ include "common.name" . }}-pg-db-migrator
309         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
310         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
311         volumeMounts:
312           - mountPath: /dbcmd-config/db_migrator_pg_policy_init.sh
313             name: {{ include "common.fullname" . }}-config
314             subPath: db_migrator_pg_policy_init.sh
315         command:
316           - /bin/sh
317           - -cx
318           - |
319              {{- if include "common.onServiceMesh" . }}
320              echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
321              /dbcmd-config/db_migrator_pg_policy_init.sh
322         env:
323         - name: SQL_HOST
324           value: "{{ .Values.postgres.service.name2 }}"
325         - name: SQL_USER
326           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "pg-user-creds" "key" "login") | indent 10 }}
327         - name: SQL_PASSWORD
328           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "pg-user-creds" "key" "password") | indent 10 }}
329         - name: SQL_DB
330           value: {{ .Values.dbmigrator.schema }}
331         - name: POLICY_HOME
332           value: {{ .Values.dbmigrator.policy_home }}
333         - name: SCRIPT_DIRECTORY
334           value: "postgres"
335         - name: PGPASSWORD
336           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "pg-user-creds" "key" "password") | indent 10 }}
337         resources: {{ include "common.resources" . | nindent 10 }}
338       {{- if (include "common.onServiceMesh" .) }}
339       - name: policy-service-mesh-wait-for-job-container
340         image: {{ include "repositoryGenerator.image.quitQuit" . }}
341         imagePullPolicy: Always
342         command:
343         - /bin/sh
344         - "-c"
345         args:
346         - echo "waiting 10s for istio side cars to be up"; sleep 10s;
347           /app/ready.py --service-mesh-check {{ include "common.name" . }}-pg-db-migrator -t 45;
348         env:
349         - name: NAMESPACE
350           valueFrom:
351             fieldRef:
352               apiVersion: v1
353               fieldPath: metadata.namespace
354       {{- end }}
355       restartPolicy: Never
356       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
357       volumes:
358         - name: {{ include "common.fullname" . }}-config
359           configMap:
360             name: {{ include "common.fullname" . }}-db-configmap
361             defaultMode: 0755
362             items:
363               - key: db_migrator_pg_policy_init.sh
364                 path: db_migrator_pg_policy_init.sh
365 {{ end }}