Merge "[AAI] Add model-loader tracing config"
[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         - --service-name
109         - {{ .Values.global.cassandra.serviceName }}
110         - --service-name
111         - aai-schema-service
112           {{- end }}
113         {{- end }}
114         env:
115         - name: NAMESPACE
116           valueFrom:
117             fieldRef:
118               apiVersion: v1
119               fieldPath: metadata.namespace
120         image: {{ include "repositoryGenerator.image.readiness" . }}
121         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
122         resources:
123           limits:
124             cpu: "100m"
125             memory: "500Mi"
126           requests:
127             cpu: "3m"
128             memory: "20Mi"
129       containers:
130       - name: {{ include "common.name" . }}
131         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
132         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
133         command:
134         - sh
135         args:
136         - -c
137         - |
138           echo "*** actual launch of AAI Resources"
139           /bin/bash /opt/app/aai-resources/docker-entrypoint.sh
140         env:
141         {{- if .Values.config.env }}
142         {{- range $key,$value := .Values.config.env }}
143         - name: {{ $key | upper | quote}}
144           value: {{ $value | quote}}
145         {{- end }}
146         {{- end }}
147         {{- if .Values.config.profiling.enabled }}
148         - name: PRE_JVM_ARGS
149           value: '{{ join " " .Values.config.profiling.args }}'
150         {{- end }}
151         {{- if .Values.config.debug.enabled }}
152         - name: POST_JVM_ARGS
153           value: {{ .Values.config.debug.args | quote }}
154         {{- end }}
155         - name: LOCAL_USER_ID
156           value: {{ .Values.global.config.userId | quote }}
157         - name: LOCAL_GROUP_ID
158           value: {{ .Values.global.config.groupId | quote }}
159         - name: INTERNAL_PORT_1
160           value: {{ .Values.service.internalPort | quote }}
161         - name: INTERNAL_PORT_2
162           value: {{ .Values.service.internalPort2 | quote }}
163         - name: INTERNAL_PORT_3
164           value: {{ .Values.service.internalPort3 | quote }}
165         volumeMounts:
166         - mountPath: /opt/app/aai-resources/resources/etc/appprops/janusgraph-realtime.properties
167           name: {{ include "common.fullname" . }}-config
168           subPath: janusgraph-realtime.properties
169         - mountPath: /opt/app/aai-resources/resources/etc/appprops/janusgraph-cached.properties
170           name: {{ include "common.fullname" . }}-config
171           subPath: janusgraph-cached.properties
172         - mountPath: /opt/app/aai-resources/resources/etc/appprops/aaiconfig.properties
173           name: {{ include "common.fullname" . }}-config
174           subPath: aaiconfig.properties
175         - mountPath: /opt/aai/logroot/AAI-RES
176           name: logs
177         - mountPath: /opt/app/aai-resources/resources/logback.xml
178           name: {{ include "common.fullname" . }}-config
179           subPath: logback.xml
180         - mountPath: /opt/app/aai-resources/resources/localhost-access-logback.xml
181           name: {{ include "common.fullname" . }}-config
182           subPath: localhost-access-logback.xml
183         - mountPath: /opt/app/aai-resources/resources/etc/auth/realm.properties
184           name: {{ include "common.fullname" . }}-config
185           subPath: realm.properties
186         - mountPath: /opt/app/aai-resources/resources/application.properties
187           name: {{ include "common.fullname" . }}-config
188           subPath: application.properties
189         - mountPath: /opt/app/aai-resources/resources/application-keycloak.properties
190           name: {{ include "common.fullname" . }}-config
191           subPath: application-keycloak.properties
192         ports:
193         - containerPort: {{ .Values.service.internalPort }}
194           name: {{ .Values.service.portName }}
195         {{- if .Values.config.debug.enabled }}
196         - containerPort: {{ .Values.service.internalPort2 }}
197           name: {{ .Values.service.portName2 }}
198         {{- end }}
199         - containerPort: {{ .Values.service.internalPort3 }}
200           name: {{ .Values.service.portName3 }}
201         {{- if .Values.config.profiling.enabled }}
202         - containerPort: {{ .Values.service.internalPort4 }}
203           name: {{ .Values.service.portName4 }}
204         {{- end }}
205
206         lifecycle:
207           # wait for active requests (long-running tasks) to be finished
208           # Before the SIGTERM is invoked, Kubernetes exposes a preStop hook in the Pod.
209           preStop:
210             exec:
211               command:
212                 - sh
213                 - -c
214                 - |
215                   while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2)
216                   do sleep 10
217                   done
218         # disable liveness probe when breakpoints set in debugger
219         # so K8s doesn't restart unresponsive container
220         {{- if .Values.liveness.enabled }}
221         livenessProbe:
222           httpGet:
223             path: /aai/util/echo?action=checkDB
224             port: {{ .Values.service.internalPort }}
225             scheme: HTTP
226             httpHeaders:
227             - name: X-FromAppId
228               value: LivenessCheck
229             - name: X-TransactionId
230               value: LiveCheck_TID
231             - name: Accept
232               value: application/json
233           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
234           periodSeconds: {{ .Values.liveness.periodSeconds }}
235         {{- end }}
236         readinessProbe:
237           httpGet:
238             path: /aai/util/echo?action=checkDB
239             port: {{ .Values.service.internalPort }}
240             scheme: HTTP
241             httpHeaders:
242             - name: X-FromAppId
243               value: ReadinessCheck
244             - name: X-TransactionId
245               value: ReadinessCheck_TID
246             - name: Accept
247               value: application/json
248           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
249           periodSeconds: {{ .Values.readiness.periodSeconds }}
250         resources: {{ include "common.resources" . | nindent 10 }}
251       {{- if .Values.nodeSelector }}
252       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
253       {{- end }}
254       {{- if .Values.affinity }}
255       affinity: {{ toYaml .Values.affinity | nindent 8 }}
256       {{- end }}
257       # side car containers
258       {{ include "common.log.sidecar" . | nindent 6 }}
259       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
260       volumes:
261       - name: logs
262         emptyDir: {}
263       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 6 }}
264       - name: {{ include "common.fullname" . }}-config
265         configMap:
266           name: {{ include "common.fullname" . }}
267       restartPolicy: {{ .Values.restartPolicy }}
268       {{- include "common.imagePullSecrets" . | nindent 6 }}