[AAI] Fix Istio compatibility and add Job ServiceAccount
[oom.git] / kubernetes / aai / components / aai-resources / templates / deployment.yaml
1 {{/*
2 # Copyright (c) 2017 Amdocs, Bell Canada
3 # Modifications Copyright (c) 2018 AT&T
4 # Modifications Copyright (c) 2020 Nokia
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": "8447",
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": "8447",
84               "enable_ssl": true,
85               "lb_policy":"ip_hash",
86               "visualRange": "1"
87           },
88           {{- end }}
89         {{- end }}
90           ]'
91       {{- end }}
92     spec:
93       hostname: aai-resources
94       terminationGracePeriodSeconds: {{ .Values.service.terminationGracePeriodSeconds }}
95       initContainers:
96       - name: {{ include "common.name" . }}-readiness
97         command:
98         - /app/ready.py
99         args:
100         {{- if .Values.global.jobs.migration.enabled }}
101         - --job-name
102         - {{ include "common.release" . }}-aai-graphadmin-migration
103         {{- else }}
104           {{- if .Values.global.jobs.createSchema.enabled  }}
105         - --job-name
106         - {{ include "common.release" . }}-aai-graphadmin-create-db-schema
107           {{- else }}
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           {{- end }}
117         {{- end }}
118         env:
119         - name: NAMESPACE
120           valueFrom:
121             fieldRef:
122               apiVersion: v1
123               fieldPath: metadata.namespace
124         image: {{ include "repositoryGenerator.image.readiness" . }}
125         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
126       containers:
127       - name: {{ include "common.name" . }}
128         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
129         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
130         command:
131         - sh
132         args:
133         - -c
134         - |
135           echo "*** actual launch of AAI Resources"
136           /bin/bash /opt/app/aai-resources/docker-entrypoint.sh
137         env:
138         - name: LOCAL_USER_ID
139           value: {{ .Values.global.config.userId | quote }}
140         - name: LOCAL_GROUP_ID
141           value: {{ .Values.global.config.groupId | quote }}
142         - name: INTERNAL_PORT_1
143           value: {{ .Values.service.internalPort | quote }}
144         - name: INTERNAL_PORT_2
145           value: {{ .Values.service.internalPort2 | quote }}
146         - name: INTERNAL_PORT_3
147           value: {{ .Values.service.internalPort3 | quote }}
148         volumeMounts:
149         - mountPath: /etc/localtime
150           name: localtime
151           readOnly: true
152         - mountPath: /opt/app/aai-resources/resources/etc/appprops/janusgraph-realtime.properties
153           name: {{ include "common.fullname" . }}-config
154           subPath: janusgraph-realtime.properties
155         - mountPath: /opt/app/aai-resources/resources/etc/appprops/janusgraph-cached.properties
156           name: {{ include "common.fullname" . }}-config
157           subPath: janusgraph-cached.properties
158         - mountPath: /opt/app/aai-resources/resources/etc/appprops/aaiconfig.properties
159           name: {{ include "common.fullname" . }}-config
160           subPath: aaiconfig.properties
161         - mountPath: /opt/aai/logroot/AAI-RES
162           name: logs
163         - mountPath: /opt/app/aai-resources/resources/logback.xml
164           name: {{ include "common.fullname" . }}-config
165           subPath: logback.xml
166         - mountPath: /opt/app/aai-resources/resources/localhost-access-logback.xml
167           name: {{ include "common.fullname" . }}-config
168           subPath: localhost-access-logback.xml
169         - mountPath: /opt/app/aai-resources/resources/etc/auth/realm.properties
170           name: {{ include "common.fullname" . }}-config
171           subPath: realm.properties
172         - mountPath: /opt/app/aai-resources/resources/application.properties
173           name: {{ include "common.fullname" . }}-config
174           subPath: application.properties
175         - mountPath: /opt/app/aai-resources/resources/application-keycloak.properties
176           name: {{ include "common.fullname" . }}-config
177           subPath: application-keycloak.properties
178         ports:
179         - containerPort: {{ .Values.service.internalPort }}
180           name: {{ .Values.service.portName }}
181         - containerPort: {{ .Values.service.internalPort2 }}
182           name: {{ .Values.service.portName2 }}
183         - containerPort: {{ .Values.service.internalPort3 }}
184           name: {{ .Values.service.portName3 }}
185         lifecycle:
186           # wait for active requests (long-running tasks) to be finished
187           # Before the SIGTERM is invoked, Kubernetes exposes a preStop hook in the Pod.
188           preStop:
189             exec:
190               command:
191                 - sh
192                 - -c
193                 - |
194                   while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2)
195                   do sleep 10
196                   done
197         # disable liveness probe when breakpoints set in debugger
198         # so K8s doesn't restart unresponsive container
199         {{- if .Values.liveness.enabled }}
200         livenessProbe:
201           httpGet:
202             path: /aai/util/echo?action=checkDB
203             port: {{ .Values.service.internalPort }}
204             scheme: HTTP
205             httpHeaders:
206             - name: X-FromAppId
207               value: LivenessCheck
208             - name: X-TransactionId
209               value: LiveCheck_TID
210             - name: Accept
211               value: application/json
212           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
213           periodSeconds: {{ .Values.liveness.periodSeconds }}
214         {{- end }}
215         readinessProbe:
216           httpGet:
217             path: /aai/util/echo?action=checkDB
218             port: {{ .Values.service.internalPort }}
219             scheme: HTTP
220             httpHeaders:
221             - name: X-FromAppId
222               value: ReadinessCheck
223             - name: X-TransactionId
224               value: ReadinessCheck_TID
225             - name: Accept
226               value: application/json
227           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
228           periodSeconds: {{ .Values.readiness.periodSeconds }}
229         resources: {{ include "common.resources" . | nindent 10 }}
230       {{- if .Values.nodeSelector }}
231       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
232       {{- end }}
233       {{- if .Values.affinity }}
234       affinity: {{ toYaml .Values.affinity | nindent 8 }}
235       {{- end }}
236       # side car containers
237       {{ include "common.log.sidecar" . | nindent 6 }}
238       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
239       volumes:
240       - name: localtime
241         hostPath:
242           path: /etc/localtime
243       - name: logs
244         emptyDir: {}
245       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 6 }}
246       - name: {{ include "common.fullname" . }}-config
247         configMap:
248           name: {{ include "common.fullname" . }}
249       restartPolicy: {{ .Values.restartPolicy }}
250       imagePullSecrets:
251       - name: "{{ include "common.namespace" . }}-docker-registry-key"