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