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