Merge "[AAI] Kyverno - disallow-host-path policy"
[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 # Modifications Copyright © 2023 Nordix Foundation
10 # ================================================================================
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14 #
15 #    http://www.apache.org/licenses/LICENSE-2.0
16 #
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22 # ============LICENSE_END=========================================================
23
24 # In ONAP, the following job will always be run on each installation
25 # The following job will go through the latest oxm and
26 # create properties based on the data type defined in the oxm
27 # and create the required indexes for the appropriate properties
28 # This can be run multiple times as the code if the index or property already exists
29 # then the index or property won't be created again
30 # NOTE - During the execution of the createSchema job, there should
31 # be no other janusgraph connection to the graph as its the reason
32 # that resources traversal and graphadmin wait until this job is done
33 # If you are using an existing cassandra cluster not coming from oom
34 # then it is your job to ensure that there are no connections to the database
35 */}}
36
37 {{- if .Values.global.jobs.migration.enabled }}
38 ---
39 apiVersion: batch/v1
40 kind: Job
41 metadata:
42   name: {{ include "common.fullname" . }}-migration
43   namespace: {{ include "common.namespace" . }}
44   labels:
45     app: {{ include "common.name" . }}-job
46     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
47     release: {{ include "common.release" . }}
48     heritage: {{ .Release.Service }}
49   annotations:
50     "helm.sh/hook": post-upgrade,post-rollback,post-install
51     "helm.sh/hook-weight": "1"
52     "helm.sh/hook-delete-policy": before-hook-creation
53 spec:
54   backoffLimit: 20
55   template:
56     metadata:
57       labels:
58         app: {{ include "common.name" . }}-job
59         release: {{ include "common.release" . }}
60       name: {{ include "common.name" . }}
61     spec:
62       initContainers:
63       - command:
64         - /app/ready.py
65         args:
66         - --app-name
67         {{- if .Values.global.cassandra.localCluster }}
68         - aai-cassandra
69         {{- else }}
70         - cassandra
71         {{- end }}
72         - --container-name
73         - aai-schema-service
74         env:
75         - name: NAMESPACE
76           valueFrom:
77             fieldRef:
78               apiVersion: v1
79               fieldPath: metadata.namespace
80         image: {{ include "repositoryGenerator.image.readiness" . }}
81         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
82         name: {{ include "common.name" . }}-readiness
83         resources:
84           limits:
85             cpu: "100m"
86             memory: "500Mi"
87           requests:
88             cpu: "3m"
89             memory: "20Mi"
90       - command:
91         - sh
92         args:
93         - -c
94         - |
95            bash docker-entrypoint.sh dataRestoreFromSnapshot.sh `ls -t /opt/app/aai-graphadmin/logs/data/dataSnapshots|head -1|awk -F".P" '{ print $1 }'`
96         env:
97         - name: LOCAL_USER_ID
98           value: {{ .Values.securityContext.user_id | quote }}
99         - name: LOCAL_GROUP_ID
100           value: {{ .Values.securityContext.group_id | quote }}
101         volumeMounts:
102         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
103           name: config
104           subPath: janusgraph-realtime.properties
105         - mountPath: /opt/app/aai-graphadmin/logs/data/dataSnapshots
106           name: snapshots
107         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
108           name: config
109           subPath: janusgraph-cached.properties
110         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
111           name: properties
112           subPath: aaiconfig.properties
113         - mountPath: /opt/aai/logroot/AAI-GA
114           name: logs
115         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
116           name: config
117           subPath: logback.xml
118         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
119           name: config
120           subPath: localhost-access-logback.xml
121         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
122           name: properties
123           subPath: application.properties
124         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
125         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
126         name: {{ include "common.name" . }}-restore-backup
127       containers:
128       - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
129         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
130         name: {{ include "common.name" . }}-perform-migration
131         command:
132         - sh
133         args:
134         - -c
135         - |
136            {{- if include "common.onServiceMesh" . }}
137            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
138            bash docker-entrypoint.sh run_Migrations.sh -e UpdateAaiUriIndexMigration --commit --skipPreMigrationSnapShot --runDisabled RebuildAllEdges ;
139            {{ include "common.serviceMesh.killSidecar" . | indent 11 | trim }}
140         env:
141         - name: LOCAL_USER_ID
142           value: {{ .Values.securityContext.user_id | quote }}
143         - name: LOCAL_GROUP_ID
144           value: {{ .Values.securityContext.group_id | quote }}
145         volumeMounts:
146         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
147           name: config
148           subPath: janusgraph-realtime.properties
149         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
150           name: config
151           subPath: janusgraph-cached.properties
152         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
153           name: properties
154           subPath: aaiconfig.properties
155         - mountPath: /opt/aai/logroot/AAI-GA
156           name: logs
157         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
158           name: config
159           subPath: logback.xml
160         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
161           name: config
162           subPath: localhost-access-logback.xml
163         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
164           name: properties
165           subPath: application.properties
166         resources: {{ include "common.resources" . | nindent 10 }}
167       {{- if .Values.nodeSelector }}
168       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
169       {{- end }}
170       {{- if .Values.affinity }}
171       affinity: {{ toYaml .Values.affinity | nindent 8 }}
172       {{- end }}
173       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
174       volumes:
175       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 8 }}
176       - name: {{ include "common.fullname" . }}-logs
177         emptyDir: {}
178       - name: {{ include "common.fullname" . }}-config
179         configMap:
180           name: {{ include "common.fullname" . }}-configmap
181       - name: {{ include "common.fullname" . }}-snapshots
182         persistentVolumeClaim:
183           claimName: {{ include "common.fullname" . }}-migration
184       - name: properties
185         configMap:
186           name: {{ include "common.fullname" . }}-properties
187       restartPolicy: Never
188       {{- include "common.imagePullSecrets" . | nindent 6 }}
189 ---
190 apiVersion: batch/v1
191 kind: Job
192 metadata:
193   name: {{ include "common.fullname" . }}-db-backup-job
194   namespace: {{ include "common.namespace" . }}
195   labels:
196     app: {{ include "common.name" . }}-db-backup-job
197     release: {{ include "common.release" . }}
198     heritage: {{ .Release.Service }}
199     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
200   annotations:
201     "helm.sh/hook": pre-upgrade,pre-install
202     "helm.sh/hook-weight": "2"
203     "helm.sh/hook-delete-policy": before-hook-creation
204 spec:
205   backoffLimit: 20
206   template:
207     metadata:
208       labels:
209         app: {{ include "common.name" . }}-db-backup-job
210         release: {{ include "common.release" . }}
211       name: {{ include "common.name" . }}
212     spec:
213       initContainers:
214       {{ if eq .Values.global.jobs.migration.remoteCassandra.enabled false }}
215       - command:
216         - /bin/bash
217         - -c
218         - /app/ready.py --app-name aai-cassandra --timeout 1 || /app/ready.py --app-name cassandra
219         env:
220         - name: NAMESPACE
221           valueFrom:
222             fieldRef:
223               apiVersion: v1
224               fieldPath: metadata.namespace
225         image: {{ include "repositoryGenerator.image.readiness" . }}
226         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
227         name: {{ include "common.name" . }}-db-backup-readiness
228         resources:
229           limits:
230             cpu: "100m"
231             memory: "500Mi"
232           requests:
233             cpu: "3m"
234             memory: "20Mi"
235       {{- end }}
236       containers:
237       - name: {{ include "common.name" . }}-db-backup-job
238         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
239         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
240         command:
241         - sh
242         args:
243         - -c
244         - |
245            {{- if include "common.onServiceMesh" . }}
246            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
247            bash docker-entrypoint.sh dataSnapshot.sh
248            {{ include "common.serviceMesh.killSidecar" . | indent 11 | trim }}
249         env:
250         - name: LOCAL_USER_ID
251           value: {{ .Values.securityContext.user_id | quote }}
252         - name: LOCAL_GROUP_ID
253           value: {{ .Values.securityContext.group_id | quote }}
254         volumeMounts:
255         - mountPath: /opt/app/aai-graphadmin/logs/data/dataSnapshots
256           name: snapshots
257         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
258           name: migration
259           subPath: janusgraph-migration-real.properties
260         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
261           name: migration
262           subPath: janusgraph-migration-cached.properties
263         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
264           name: properties
265           subPath: aaiconfig.properties
266         - mountPath: /opt/aai/logroot/AAI-RES/
267           name: logs
268         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
269           name: config
270           subPath: logback.xml
271         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
272           name: config
273           subPath: localhost-access-logback.xml
274         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
275           name: properties
276           subPath: application.properties
277         resources: {{ include "common.resources" . | nindent 10 }}
278       {{- if .Values.nodeSelector }}
279       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
280       {{- end }}
281       {{- if .Values.affinity }}
282       affinity: {{ toYaml .Values.affinity | nindent 8 }}
283       {{- end }}
284       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
285       volumes: {{ include "common.resources" . | nindent 10 }}
286       - name: logs
287         emptyDir: {}
288       - name: config
289         configMap:
290           name: {{ include "common.fullname" . }}
291       - name: properties-input
292         configMap:
293           name: {{ include "common.fullname" . }}-properties
294       - name: properties
295         emptyDir:
296           medium: Memory
297       - name: migration
298         configMap:
299           name: {{ include "common.fullname" . }}-migration
300       - name: snapshots
301         persistentVolumeClaim:
302           claimName: {{ include "common.fullname" . }}-migration
303       restartPolicy: Never
304       {{- include "common.imagePullSecrets" . | nindent 6 }}
305 {{ end }}