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