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