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