[AAI] Fix Istio compatibility and add Job ServiceAccount
[oom.git] / kubernetes / aai / components / aai-traversal / templates / deployment.yaml
1 {{/*
2 # Copyright (c) 2017 Amdocs, Bell Canada
3 # Modifications Copyright (c) 2018 AT&T
4 # Modifications Copyright (c) 2020 Nokia, Orange
5 # Modifications Copyright (c) 2021 Orange
6 # Modifications Copyright © 2023 Nordix Foundation
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #       http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 */}}
20
21 apiVersion: apps/v1
22 kind: Deployment
23 metadata:
24   name: {{ include "common.fullname" . }}
25   namespace: {{ include "common.namespace" . }}
26   labels:
27     app: {{ include "common.name" . }}
28     app.kubernetes.io/name: {{ include "common.name" . }}
29     {{- if .Chart.AppVersion }}
30     version: {{ .Chart.AppVersion | replace "+" "_" }}
31     {{- else }}
32     version: {{ .Chart.Version | replace "+" "_" }}
33     {{- end }}
34     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
35     release: {{ include "common.release" . }}
36     heritage: {{ .Release.Service }}
37 spec:
38   replicas: {{ .Values.replicaCount }}
39   minReadySeconds: {{ .Values.minReadySeconds }}
40   strategy:
41     type: {{ .Values.updateStrategy.type }}
42     rollingUpdate:
43       maxUnavailable: {{ .Values.updateStrategy.maxUnavailable }}
44       maxSurge: {{ .Values.updateStrategy.maxSurge }}
45   selector:
46     matchLabels:
47       app: {{ include "common.name" . }}
48   template:
49     metadata:
50       labels:
51         app: {{ include "common.name" . }}
52         release: {{ include "common.release" . }}
53         app.kubernetes.io/name: {{ include "common.name" . }}
54         {{- if .Chart.AppVersion }}
55         version: {{ .Chart.AppVersion | replace "+" "_" }}
56         {{- else }}
57         version: {{ .Chart.Version | replace "+" "_" }}
58         {{- end }}
59       name: {{ include "common.name" . }}
60       annotations:
61         checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
62       {{- if .Values.global.msbEnabled }}
63         {{ $values := .Values }}
64         msb.onap.org/service-info: '[
65         {{- range $api_endpoint := $values.aai_enpoints -}}
66           {{- range $api_version := $values.api_list }}
67           {
68               "serviceName": "_{{ $api_endpoint.name }}",
69               "version": "v{{ $api_version }}",
70               "url": "/aai/v{{ $api_version }}/{{ $api_endpoint.url }}",
71               "protocol": "REST",
72               "port": "8446",
73               "enable_ssl": true,
74               "lb_policy":"ip_hash",
75               "visualRange": "1",
76               "path": "/aai/v{{ $api_version }}/{{ $api_endpoint.url }}"
77           },
78           {
79               "serviceName": "{{ $api_endpoint.name }}",
80               "version": "v{{ $api_version }}",
81               "url": "/aai/v{{ $api_version }}/{{ $api_endpoint.url }}",
82               "protocol": "REST",
83               "port": "8446",
84               "enable_ssl": true,
85               "lb_policy":"ip_hash",
86               "visualRange": "1"
87           },
88           {{- end }}
89         {{- end }}
90           {
91               "serviceName": "_aai-named-query",
92               "url": "/aai/search",
93               "protocol": "REST",
94               "port": "8446",
95               "enable_ssl": true,
96               "lb_policy":"ip_hash",
97               "visualRange": "1",
98               "path": "/aai/search"
99           },
100           {
101               "serviceName": "aai-named-query",
102               "url": "/aai/search",
103               "protocol": "REST",
104               "port": "8446",
105               "enable_ssl": true,
106               "lb_policy":"ip_hash",
107               "visualRange": "1"
108           }
109           ]'
110       {{- end }}
111     spec:
112       hostname: aai-traversal
113       terminationGracePeriodSeconds: {{ .Values.service.terminationGracePeriodSeconds }}
114       initContainers:
115       - command:
116         - /app/ready.py
117         args:
118       {{- if .Values.global.jobs.migration.enabled }}
119         - --job-name
120         - {{ include "common.release" . }}-aai-graphadmin-migration
121       {{- else  }}
122         {{- if .Values.global.jobs.createSchema.enabled  }}
123         - --job-name
124         - {{ include "common.release" . }}-aai-graphadmin-create-db-schema
125         {{- else }}
126         - --container-name
127           {{- if .Values.global.cassandra.localCluster }}
128         - aai-cassandra
129           {{- else }}
130         - cassandra
131           {{- end }}
132         - --container-name
133         - aai-schema-service
134         {{- end }}
135       {{- end }}
136         env:
137         - name: NAMESPACE
138           valueFrom:
139             fieldRef:
140               apiVersion: v1
141               fieldPath: metadata.namespace
142         image: {{ include "repositoryGenerator.image.readiness" . }}
143         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
144         name: {{ include "common.name" . }}-readiness
145       containers:
146       - name: {{ include "common.name" . }}
147         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
148         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
149         command:
150         - sh
151         args:
152         - -c
153         - |
154           echo "*** actual launch of AAI Resources"
155           /bin/bash /opt/app/aai-traversal/docker-entrypoint.sh
156         env:
157         - name: DISABLE_UPDATE_QUERY
158           value: {{ .Values.config.disableUpdateQuery | quote }}
159         - name: LOCAL_USER_ID
160           value: {{ .Values.global.config.userId | quote }}
161         - name: LOCAL_GROUP_ID
162           value: {{ .Values.global.config.groupId | quote }}
163         - name: INTERNAL_PORT_1
164           value: {{ .Values.service.internalPort | quote }}
165         - name: INTERNAL_PORT_2
166           value: {{ .Values.service.internalPort2 | quote }}
167         - name: INTERNAL_PORT_3
168           value: {{ .Values.service.internalPort3 | quote }}
169         volumeMounts:
170         - mountPath: /etc/localtime
171           name: localtime
172           readOnly: true
173         - mountPath: /opt/app/aai-traversal/resources/etc/appprops/janusgraph-realtime.properties
174           name: {{ include "common.fullname" . }}-config
175           subPath: janusgraph-realtime.properties
176         - mountPath: /opt/app/aai-traversal/resources/etc/appprops/janusgraph-cached.properties
177           name: {{ include "common.fullname" . }}-config
178           subPath: janusgraph-cached.properties
179         - mountPath: /opt/app/aai-traversal/resources/etc/appprops/aaiconfig.properties
180           name: {{ include "common.fullname" . }}-config
181           subPath: aaiconfig.properties
182         - mountPath: /opt/aai/logroot/AAI-GQ
183           name: logs
184         - mountPath: /opt/aai/logroot/AAI-GQ/misc
185           name: {{ include "common.fullname" . }}-logs-misc
186         - mountPath: /opt/app/aai-traversal/resources/logback.xml
187           name: {{ include "common.fullname" . }}-config
188           subPath: logback.xml
189         - mountPath: /opt/app/aai-traversal/resources/localhost-access-logback.xml
190           name: {{ include "common.fullname" . }}-config
191           subPath: localhost-access-logback.xml
192         - mountPath: /opt/app/aai-traversal/resources/etc/auth/realm.properties
193           name: {{ include "common.fullname" . }}-config
194           subPath: realm.properties
195         - mountPath: /opt/app/aai-traversal/resources/application.properties
196           name: {{ include "common.fullname" . }}-config
197           subPath: application.properties
198         - mountPath: /opt/app/aai-traversal/resources/application-keycloak.properties
199           name: {{ include "common.fullname" . }}-config
200           subPath: application-keycloak.properties
201         ports:
202         - containerPort: {{ .Values.service.internalPort }}
203           name: {{ .Values.service.portName }}
204         - containerPort: {{ .Values.service.internalPort2 }}
205           name: {{ .Values.service.portName2 }}
206         - containerPort: {{ .Values.service.internalPort3 }}
207           name: {{ .Values.service.portName3 }}
208         lifecycle:
209           # wait for active requests (long-running tasks) to be finished
210           # Before the SIGTERM is invoked, Kubernetes exposes a preStop hook in the Pod.
211           preStop:
212             exec:
213               command:
214                 - sh
215                 - -c
216                 - |
217                   while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2)
218                   do sleep 10
219                   done
220         # disable liveness probe when breakpoints set in debugger
221         # so K8s doesn't restart unresponsive container
222         {{ if .Values.liveness.enabled }}
223         livenessProbe:
224           httpGet:
225             path: /aai/util/echo?action=checkDB
226             port: {{ .Values.service.internalPort }}
227             scheme: HTTP
228             httpHeaders:
229             - name: X-FromAppId
230               value: LivenessCheck
231             - name: X-TransactionId
232               value: LiveCheck_TID
233             - name: Accept
234               value: application/json
235           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
236           periodSeconds: {{ .Values.liveness.periodSeconds }}
237         {{ end }}
238         readinessProbe:
239           httpGet:
240             path: /aai/util/echo?action=checkDB
241             port: {{ .Values.service.internalPort }}
242             scheme: HTTP
243             httpHeaders:
244             - name: X-FromAppId
245               value: ReadinessCheck
246             - name: X-TransactionId
247               value: ReadinessCheck_TID
248             - name: Accept
249               value: application/json
250           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
251           periodSeconds: {{ .Values.readiness.periodSeconds }}
252         resources: {{ include "common.resources" . | nindent 10 }}
253       {{- if .Values.nodeSelector }}
254       nodeSelector:
255 {{ toYaml .Values.nodeSelector | indent 8 }}
256       {{- end }}
257       {{- if .Values.affinity }}
258       affinity:
259 {{ toYaml .Values.affinity | indent 8 }}
260       {{- end }}
261
262       # side car containers
263       {{ include "common.log.sidecar" . | nindent 6 }}
264       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
265       volumes:
266       - name: localtime
267         hostPath:
268           path: /etc/localtime
269       - name: logs
270         emptyDir: {}
271       - name: {{ include "common.fullname" . }}-logs-misc
272         emptyDir: {}
273       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 6 }}
274       - name: {{ include "common.fullname" . }}-config
275         configMap:
276           name: {{ include "common.fullname" . }}
277       restartPolicy: {{ .Values.global.restartPolicy | default .Values.restartPolicy }}
278       imagePullSecrets:
279       - name: "{{ include "common.namespace" . }}-docker-registry-key"