Merge "[DMAAP] DMaaP ServiceMesh compatibility"
[oom.git] / kubernetes / aai / components / aai-graphadmin / templates / job-migration.yaml
1 {{/*
2 #
3 # ============LICENSE_START=======================================================
4 # org.onap.aai
5 # ================================================================================
6 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 # Copyright (c) 2020 Nokia Intellectual Property. All rights reserved.
8 # Copyright (c) 2020-2021 Orange Intellectual Property. All rights reserved.
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 #    http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
22
23 # In ONAP, the following job will always be run on each installation
24 # The following job will go through the latest oxm and
25 # create properties based on the data type defined in the oxm
26 # and create the required indexes for the appropriate properties
27 # This can be run multiple times as the code if the index or property already exists
28 # then the index or property won't be created again
29 # NOTE - During the execution of the createSchema job, there should
30 # be no other janusgraph connection to the graph as its the reason
31 # that resources traversal and graphadmin wait until this job is done
32 # If you are using an existing cassandra cluster not coming from oom
33 # then it is your job to ensure that there are no connections to the database
34 */}}
35
36 {{- if .Values.global.jobs.migration.enabled }}
37 ---
38 apiVersion: batch/v1
39 kind: Job
40 metadata:
41   name: {{ include "common.fullname" . }}-migration
42   namespace: {{ include "common.namespace" . }}
43   labels:
44     app: {{ include "common.name" . }}-job
45     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
46     release: {{ include "common.release" . }}
47     heritage: {{ .Release.Service }}
48   annotations:
49     "helm.sh/hook": post-upgrade,post-rollback,post-install
50     "helm.sh/hook-weight": "1"
51     "helm.sh/hook-delete-policy": before-hook-creation
52 spec:
53   backoffLimit: 20
54   template:
55     metadata:
56       labels:
57         app: {{ include "common.name" . }}-job
58         release: {{ include "common.release" . }}
59       name: {{ include "common.name" . }}
60     spec:
61       initContainers: {{ include "common.certInitializer.initContainer" . | nindent 6 }}
62       {{- if .Values.global.aafEnabled }}
63       - command:
64         - sh
65         args:
66         - -c
67         - |
68           echo "*** retrieve Truststore and Keystore password"
69           export $(cat {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop | xargs -0)
70           echo "*** obfuscate them "
71           export JETTY_UTIL_JAR=$(find /usr/local/jetty/lib/ -regextype sed -regex ".*jetty-util-[0-9].*.jar")
72           export KEYSTORE_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${KEYSTORE_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
73           export KEYSTORE_JKS_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${KEYSTORE_JKS_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
74           export TRUSTSTORE_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${TRUSTSTORE_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
75           echo "KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
76           echo "KEYSTORE_JKS_PASSWORD=${KEYSTORE_JKS_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
77           echo "TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
78         image: {{ include "repositoryGenerator.image.jetty" . }}
79         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
80         name: {{ include "common.name" . }}-obfuscate
81         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
82         securityContext:
83           runAsUser: {{ .Values.securityContext.user_id }}
84       - command:
85         - sh
86         args:
87         - -c
88         - |
89           echo "*** Set obfuscated Truststore and Keystore password into configuration file"
90           export $(cat {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop | xargs -0)
91           cd /config-input
92           for PFILE in `ls -1`
93           do
94             envsubst <${PFILE} >/config/${PFILE}
95           done
96         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
97         - mountPath: /config-input
98           name: properties-input
99         - mountPath: /config
100           name: properties
101         image: {{ include "repositoryGenerator.image.envsubst" . }}
102         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
103         name: {{ include "common.name" . }}-update-config
104       {{- end }}
105       - command:
106         - /app/ready.py
107         args:
108         - --container-name
109         {{- if .Values.global.cassandra.localCluster }}
110         - aai-cassandra
111         {{- else }}
112         - cassandra
113         {{- end }}
114         - --container-name
115         - aai-schema-service
116         env:
117         - name: NAMESPACE
118           valueFrom:
119             fieldRef:
120               apiVersion: v1
121               fieldPath: metadata.namespace
122         image: {{ include "repositoryGenerator.image.readiness" . }}
123         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
124         name: {{ include "common.name" . }}-readiness
125       - command:
126         - sh
127         args:
128         - -c
129         - |
130            bash docker-entrypoint.sh dataRestoreFromSnapshot.sh `ls -t /opt/app/aai-graphadmin/logs/data/dataSnapshots|head -1|awk -F".P" '{ print $1 }'`
131         env:
132         - name: LOCAL_USER_ID
133           value: {{ .Values.securityContext.user_id | quote }}
134         - name: LOCAL_GROUP_ID
135           value: {{ .Values.securityContext.group_id | quote }}
136         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
137         - mountPath: /etc/localtime
138           name: localtime
139           readOnly: true
140         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
141           name: config
142           subPath: janusgraph-realtime.properties
143         - mountPath: /opt/app/aai-graphadmin/logs/data/dataSnapshots
144           name: snapshots
145         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
146           name: config
147           subPath: janusgraph-cached.properties
148         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
149           name: properties
150           subPath: aaiconfig.properties
151         - mountPath: /opt/aai/logroot/AAI-GA
152           name: logs
153         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
154           name: config
155           subPath: logback.xml
156         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
157           name: config
158           subPath: localhost-access-logback.xml
159         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
160           name: properties
161           subPath: application.properties
162         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
163         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
164         name: {{ include "common.name" . }}-restore-backup
165       containers:
166       - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
167         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
168         name: {{ include "common.name" . }}-perform-migration
169         command:
170         - sh
171         args:
172         - -c
173         - |
174            {{- if include "common.onServiceMesh" . }}
175            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
176            bash docker-entrypoint.sh run_Migrations.sh -e UpdateAaiUriIndexMigration --commit --skipPreMigrationSnapShot --runDisabled RebuildAllEdges ;
177            {{ include "common.serviceMesh.killSidecar" . | indent 11 | trim }}
178         env:
179         - name: LOCAL_USER_ID
180           value: {{ .Values.securityContext.user_id | quote }}
181         - name: LOCAL_GROUP_ID
182           value: {{ .Values.securityContext.group_id | quote }}
183         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
184         - mountPath: /etc/localtime
185           name: localtime
186           readOnly: true
187         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
188           name: config
189           subPath: janusgraph-realtime.properties
190         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
191           name: config
192           subPath: janusgraph-cached.properties
193         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
194           name: properties
195           subPath: aaiconfig.properties
196         - mountPath: /opt/aai/logroot/AAI-GA
197           name: logs
198         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
199           name: config
200           subPath: logback.xml
201         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
202           name: config
203           subPath: localhost-access-logback.xml
204         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
205           name: properties
206           subPath: application.properties
207         resources: {{ include "common.resources" . | nindent 10 }}
208       {{- if .Values.nodeSelector }}
209       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
210       {{- end }}
211       {{- if .Values.affinity }}
212       affinity: {{ toYaml .Values.affinity | nindent 8 }}
213       {{- end }}
214       volumes: {{ include "common.certInitializer.volumes" . | nindent 6 }}
215       - name: localtime
216         hostPath:
217           path: /etc/localtime
218       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 8 }}
219       - name: {{ include "common.fullname" . }}-logs
220         emptyDir: {}
221       - name: {{ include "common.fullname" . }}-config
222         configMap:
223           name: {{ include "common.fullname" . }}-configmap
224       - name: {{ include "common.fullname" . }}-snapshots
225         persistentVolumeClaim:
226           claimName: {{ include "common.fullname" . }}-migration
227       - name: properties
228       {{- if .Values.global.aafEnabled }}
229         emptyDir:
230           medium: Memory
231       - name: properties-input
232       {{- end }}
233         configMap:
234           name: {{ include "common.fullname" . }}-properties
235       restartPolicy: Never
236       imagePullSecrets:
237       - name: "{{ include "common.namespace" . }}-docker-registry-key"
238 ---
239 apiVersion: batch/v1
240 kind: Job
241 metadata:
242   name: {{ include "common.fullname" . }}-db-backup-job
243   namespace: {{ include "common.namespace" . }}
244   labels:
245     app: {{ include "common.name" . }}-db-backup-job
246     release: {{ include "common.release" . }}
247     heritage: {{ .Release.Service }}
248     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
249   annotations:
250     "helm.sh/hook": pre-upgrade,pre-install
251     "helm.sh/hook-weight": "2"
252     "helm.sh/hook-delete-policy": before-hook-creation
253 spec:
254   backoffLimit: 20
255   template:
256     metadata:
257       labels:
258         app: {{ include "common.name" . }}-db-backup-job
259         release: {{ include "common.release" . }}
260       name: {{ include "common.name" . }}
261     spec:
262       initContainers: {{ include "common.certInitializer.initContainer" . | nindent 6 }}
263       {{- if .Values.global.aafEnabled }}
264       - command:
265         - sh
266         args:
267         - -c
268         - |
269           echo "*** retrieve Truststore and Keystore password"
270           export $(cat {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop | xargs -0)
271           echo "*** obfuscate them "
272           export JETTY_UTIL_JAR=$(find /usr/local/jetty/lib/ -regextype sed -regex ".*jetty-util-[0-9].*.jar")
273           export KEYSTORE_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${KEYSTORE_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
274           export KEYSTORE_JKS_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${KEYSTORE_JKS_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
275           export TRUSTSTORE_PASSWORD=`java -cp ${JETTY_UTIL_JAR} org.eclipse.jetty.util.security.Password ${TRUSTSTORE_PLAIN_PASSWORD} 2>&1 | grep "OBF:"`
276           echo "KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
277           echo "KEYSTORE_JKS_PASSWORD=${KEYSTORE_JKS_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
278           echo "TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD}" >> {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop
279         image: {{ include "repositoryGenerator.image.jetty" . }}
280         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
281         name: {{ include "common.name" . }}-obfuscate
282         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
283         securityContext:
284           runAsUser: {{ .Values.securityContext.user_id }}
285       - command:
286         - sh
287         args:
288         - -c
289         - |
290           echo "*** Set obfuscated Truststore and Keystore password into configuration file"
291           export $(cat {{ .Values.certInitializer.appMountPath }}/local/mycreds.prop | xargs -0)
292           cd /config-input
293           for PFILE in `ls -1`
294           do
295             envsubst <${PFILE} >/config/${PFILE}
296           done
297         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
298         - mountPath: /config-input
299           name: properties-input
300         - mountPath: /config
301           name: properties
302         image: {{ include "repositoryGenerator.image.envsubst" . }}
303         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
304         name: {{ include "common.name" . }}-update-config
305       {{- end }}
306       {{ if eq .Values.global.jobs.migration.remoteCassandra.enabled false }}
307       - command:
308         - /bin/bash
309         - -c
310         - /app/ready.py --container-name aai-cassandra --timeout 1 || /app/ready.py --container-name cassandra
311         env:
312         - name: NAMESPACE
313           valueFrom:
314             fieldRef:
315               apiVersion: v1
316               fieldPath: metadata.namespace
317         image: {{ include "repositoryGenerator.image.readiness" . }}
318         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
319         name: {{ include "common.name" . }}-db-backup-readiness
320       {{- end }}
321       containers:
322       - name: {{ include "common.name" . }}-db-backup-job
323         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
324         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
325         command:
326         - sh
327         args:
328         - -c
329         - |
330            {{- if include "common.onServiceMesh" . }}
331            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
332            bash docker-entrypoint.sh dataSnapshot.sh
333            {{ include "common.serviceMesh.killSidecar" . | indent 11 | trim }}
334         env:
335         - name: LOCAL_USER_ID
336           value: {{ .Values.securityContext.user_id | quote }}
337         - name: LOCAL_GROUP_ID
338           value: {{ .Values.securityContext.group_id | quote }}
339         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
340         - mountPath: /etc/localtime
341           name: localtime
342           readOnly: true
343         - mountPath: /opt/app/aai-graphadmin/logs/data/dataSnapshots
344           name: snapshots
345         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
346           name: migration
347           subPath: janusgraph-migration-real.properties
348         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
349           name: migration
350           subPath: janusgraph-migration-cached.properties
351         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
352           name: properties
353           subPath: aaiconfig.properties
354         - mountPath: /opt/aai/logroot/AAI-RES/
355           name: logs
356         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
357           name: config
358           subPath: logback.xml
359         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
360           name: config
361           subPath: localhost-access-logback.xml
362         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
363           name: properties
364           subPath: application.properties
365         resources: {{ include "common.resources" . | nindent 10 }}
366       {{- if .Values.nodeSelector }}
367       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
368       {{- end }}
369       {{- if .Values.affinity }}
370       affinity: {{ toYaml .Values.affinity | nindent 8 }}
371       {{- end }}
372       volumes: {{ include "common.resources" . | nindent 10 }}
373       - name: localtime
374         hostPath:
375           path: /etc/localtime
376       - name: logs
377         emptyDir: {}
378       - name: config
379         configMap:
380           name: {{ include "common.fullname" . }}
381       - name: properties-input
382         configMap:
383           name: {{ include "common.fullname" . }}-properties
384       - name: properties
385         emptyDir:
386           medium: Memory
387       - name: migration
388         configMap:
389           name: {{ include "common.fullname" . }}-migration
390       - name: snapshots
391         persistentVolumeClaim:
392           claimName: {{ include "common.fullname" . }}-migration
393       restartPolicy: Never
394       imagePullSecrets:
395       - name: "{{ include "common.namespace" . }}-docker-registry-key"
396 {{ end }}