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