Merge "[POLICY] Update docker images to latest versions"
[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       annotations:
36         sidecar.istio.io/inject: "false"
37     spec:
38       imagePullSecrets:
39       - name: "{{ include "common.namespace" . }}-docker-registry-key"
40       initContainers:
41       - name: {{ include "common.name" . }}-mariadb-readiness
42         image: {{ include "repositoryGenerator.image.readiness" . }}
43         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
44         command:
45         - /app/ready.py
46         - --container-name
47         - {{ index .Values "mariadb-galera" "service" "name" }}
48         env:
49         - name: NAMESPACE
50           valueFrom:
51             fieldRef:
52               apiVersion: v1
53               fieldPath: metadata.namespace
54       containers:
55       - name: {{ include "common.name" . }}-galera-config
56         image: {{ include "repositoryGenerator.image.mariadb" . }}
57         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
58         volumeMounts:
59         - mountPath: /dbcmd-config/db.sh
60           name: {{ include "common.fullname" . }}-config
61           subPath: db.sh
62         command:
63         - /bin/sh
64         - -cx
65         - |
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       restartPolicy: Never
78       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
79       volumes:
80         - name: {{ include "common.fullname" . }}-config
81           configMap:
82             name: {{ include "common.fullname" . }}-db-configmap
83             defaultMode: 0755
84             items:
85               - key: db.sh
86                 path: db.sh
87 {{ end }}
88
89 {{ if .Values.global.postgres.localCluster }}
90 ---
91 apiVersion: batch/v1
92 kind: Job
93 metadata:
94   name: {{ include "common.fullname" . }}-pg-init
95   namespace: {{ include "common.namespace" . }}
96   labels:
97     app: {{ include "common.name" . }}-pg-init
98     release: {{ include "common.release" . }}
99 spec:
100   template:
101     metadata:
102       labels:
103         app: {{ include "common.name" . }}-pg-init
104         release: {{ include "common.release" . }}
105       name: {{ include "common.name" . }}-pg-init
106       annotations:
107         sidecar.istio.io/inject: "false"
108     spec:
109       imagePullSecrets:
110       - name: "{{ include "common.namespace" . }}-docker-registry-key"
111       initContainers: {{ if .Values.global.postgres.localCluster }}{{ include "common.readinessCheck.waitFor" . | nindent 6 }}{{ end }}
112       containers:
113       - name: {{ include "common.name" . }}-pg-config
114         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.postgresImage }}
115         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
116         volumeMounts:
117           - mountPath: /docker-entrypoint-initdb.d/db-pg.sh
118             name: {{ include "common.fullname" . }}-config
119             subPath: db-pg.sh
120         command:
121           - /bin/sh
122           - -cx
123           - |
124              /docker-entrypoint-initdb.d/db-pg.sh
125         env:
126           - name: PG_ADMIN_PASSWORD
127             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-password" "key" "password") | indent 12 }}
128           - name: PG_HOST
129             value: "{{ .Values.postgres.service.name2 }}"
130           - name: PG_USER
131             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 12 }}
132           - name: PG_USER_PASSWORD
133             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 12 }}
134           - name: PG_PORT
135             value: "{{ .Values.postgres.service.internalPort }}"
136         resources: {{ include "common.resources" . | nindent 10 }}
137       restartPolicy: Never
138       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
139       volumes:
140         - name: {{ include "common.fullname" . }}-config
141           configMap:
142             name: {{ include "common.fullname" . }}-db-configmap
143             defaultMode: 0755
144             items:
145               - key: db-pg.sh
146                 path: db-pg.sh
147 {{ end }}
148
149 ---
150 {{ if not .Values.global.postgres.localCluster }}
151 apiVersion: batch/v1
152 kind: Job
153 metadata:
154   name: {{ include "common.fullname" . }}-galera-config
155   namespace: {{ include "common.namespace" . }}
156   labels:
157     app: {{ include "common.name" . }}-galera-config
158     release: {{ include "common.release" . }}
159 spec:
160   template:
161     metadata:
162       labels:
163         app: {{ include "common.name" . }}-galera-config
164         release: {{ include "common.release" . }}
165       name: {{ include "common.name" . }}-galera-config
166       annotations:
167         sidecar.istio.io/inject: "false"
168     spec:
169       imagePullSecrets:
170       - name: "{{ include "common.namespace" . }}-docker-registry-key"
171       initContainers:
172         - name: {{ include "common.name" . }}-init-readiness
173           image: {{ include "repositoryGenerator.image.readiness" . }}
174           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
175           command:
176           - /app/ready.py
177           args:
178           - --job-name
179           - {{ include "common.fullname" . }}-galera-init
180           env:
181           - name: NAMESPACE
182             valueFrom:
183               fieldRef:
184                 apiVersion: v1
185                 fieldPath: metadata.namespace
186       containers:
187       - name: {{ include "common.name" . }}-galera-db-migrator
188         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
189         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
190         volumeMounts:
191         - mountPath: /dbcmd-config/db_migrator_policy_init.sh
192           name: {{ include "common.fullname" . }}-config
193           subPath: db_migrator_policy_init.sh
194         command:
195         - /bin/sh
196         - -cx
197         - |
198            /dbcmd-config/db_migrator_policy_init.sh
199         env:
200         - name: SQL_HOST
201           value: "{{ index .Values "mariadb-galera" "service" "name" }}"
202         - name: SQL_USER
203           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
204         - name: SQL_PASSWORD
205           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
206         - name: SQL_DB
207           value: {{ .Values.dbmigrator.schema }}
208         - name: POLICY_HOME
209           value: {{ .Values.dbmigrator.policy_home }}
210         - name: SCRIPT_DIRECTORY
211           value: "sql"
212         resources: {{ include "common.resources" . | nindent 10 }}
213       restartPolicy: Never
214       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
215       volumes:
216         - name: {{ include "common.fullname" . }}-config
217           configMap:
218             name: {{ include "common.fullname" . }}-db-configmap
219             defaultMode: 0755
220             items:
221               - key: db_migrator_policy_init.sh
222                 path: db_migrator_policy_init.sh
223 {{ end }}
224 {{ if .Values.global.postgres.localCluster }}
225 ---
226 apiVersion: batch/v1
227 kind: Job
228 metadata:
229   name: {{ include "common.fullname" . }}-pg-config
230   namespace: {{ include "common.namespace" . }}
231   labels:
232     app: {{ include "common.name" . }}-pg-config
233     release: {{ include "common.release" . }}
234 spec:
235   template:
236     metadata:
237       labels:
238         app: {{ include "common.name" . }}-pg-config
239         release: {{ include "common.release" . }}
240       name: {{ include "common.name" . }}-pg-config
241       annotations:
242         sidecar.istio.io/inject: "false"
243     spec:
244       imagePullSecrets:
245       - name: "{{ include "common.namespace" . }}-docker-registry-key"
246       initContainers:
247         - name: {{ include "common.name" . }}-init-readiness
248           image: {{ include "repositoryGenerator.image.readiness" . }}
249           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
250           command:
251           - /app/ready.py
252           args:
253           - --job-name
254           - {{ include "common.fullname" . }}-pg-init
255           env:
256           - name: NAMESPACE
257             valueFrom:
258               fieldRef:
259                 apiVersion: v1
260                 fieldPath: metadata.namespace
261       containers:
262       - name: {{ include "common.name" . }}-pg-db-migrator
263         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dbmigrator.image }}
264         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
265         volumeMounts:
266           - mountPath: /dbcmd-config/db_migrator_pg_policy_init.sh
267             name: {{ include "common.fullname" . }}-config
268             subPath: db_migrator_pg_policy_init.sh
269         command:
270           - /bin/sh
271           - -cx
272           - |
273              /dbcmd-config/db_migrator_pg_policy_init.sh
274         env:
275         - name: SQL_HOST
276           value: "{{ .Values.postgres.service.name2 }}"
277         - name: SQL_USER
278           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "login") | indent 10 }}
279         - name: SQL_PASSWORD
280           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
281         - name: SQL_DB
282           value: {{ .Values.dbmigrator.schema }}
283         - name: POLICY_HOME
284           value: {{ .Values.dbmigrator.policy_home }}
285         - name: SCRIPT_DIRECTORY
286           value: "postgres"
287         - name: PGPASSWORD
288           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-secret" "key" "password") | indent 10 }}
289         resources: {{ include "common.resources" . | nindent 10 }}
290       restartPolicy: Never
291       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
292       volumes:
293         - name: {{ include "common.fullname" . }}-config
294           configMap:
295             name: {{ include "common.fullname" . }}-db-configmap
296             defaultMode: 0755
297             items:
298               - key: db_migrator_pg_policy_init.sh
299                 path: db_migrator_pg_policy_init.sh
300 {{ end }}