E2T: implement K8S health check
[ric-plt/ric-dep.git] / helm / e2term / templates / deployment.yaml
1 ################################################################################
2 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
3 #   Copyright (c) 2019 Nokia.                                                  #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 {{- $topCtx :=  . }}
18 {{- $health := .Values.health }}
19 {{- range keys .Values.e2term }}
20 {{- $key := . }}
21 {{- with index $topCtx.Values.e2term . }}
22
23 {{- $imagectx := dict "ctx" $topCtx "defaultregistry" .image.registry }}
24 {{- $pullpolicyctx := dict "ctx" $topCtx "defaultpullpolicy" .imagePullPolicy }}
25 ---
26 apiVersion: apps/v1
27 kind: Deployment
28 metadata:
29   name: {{ include "common.deploymentname.e2term" $topCtx }}-{{ $key }}
30   namespace: {{ include "common.namespace.platform" $topCtx }}
31   labels:
32     app: {{ include "common.namespace.platform" $topCtx }}-{{ include "common.name.e2term" $topCtx }}
33     chart: {{ $topCtx.Chart.Name }}-{{ $topCtx.Chart.Version | replace "+" "_" }}
34     release: {{ $topCtx.Release.Name }}
35     heritage: {{ $topCtx.Release.Service }}
36 spec:
37   replicas: {{ .replicaCount }}
38   selector:
39     matchLabels:
40       app: {{ include "common.namespace.platform" $topCtx }}-{{ include "common.name.e2term" $topCtx }}
41       release: {{ $topCtx.Release.Name }}
42   template:
43     metadata:
44         {{- if $.Values.global }}
45           {{- if $.Values.global.danm_networks }}
46             {{- $networklist := list }}
47             {{- range $network := $.Values.global.danm_networks }}
48               {{- if $network.tenants }}
49                 {{- if $network.tenants.e2term }}
50                   {{- if (hasKey $network.tenants.e2term $key) }}
51                     {{- $networklist = append $networklist $network }}
52                   {{- end }}
53                 {{- end }}
54               {{- end }}
55             {{- end }}
56             {{- if $networklist }}
57       annotations:
58         danm.k8s.io/interfaces: |
59           [
60             {{- range $network := $networklist }}
61               {{- printf "\n            {\"clusterNetwork\": \"%s\"" $network.name }}
62               {{- with index $network.tenants.e2term $key }}
63               {{- if .ip }}
64                 {{- printf ", \"ip\": \"%s\"" .ip }}
65               {{- else }}
66                 {{- printf ", \"ip\": \"dynamic\"" }}
67               {{- end }}
68               {{- if .ip6 }}
69                 {{- printf ", \"ip6\": \"%s\"" .ip6 }}
70               {{- end }}
71               {{- if .proutes }}
72                 {{- printf ", \"proutes\": {" }}
73                 {{- range $subnet, $gw := .proutes }}
74                   {{- if eq $subnet ( first ( keys .proutes ))}}
75                     {{- printf "\"%s\": \"%s\"" $subnet $gw }}
76                   {{- else }}
77                     {{- printf ", \"%s\": \"%s\"" $subnet $gw }}
78                   {{- end }}
79                 {{- end }}
80                 {{- printf "}" }}
81               {{- end }}
82               {{- end }}
83               {{- if ne $network.name (last $networklist).name }}
84               {{- printf "}," }}
85               {{- else }}
86               {{- printf "}" }}
87               {{- end }}
88             {{- end }}
89           ]
90             {{- end }}
91           {{- end }}
92         {{- end }}
93       labels:
94         app: {{ include "common.namespace.platform" $topCtx }}-{{ include "common.name.e2term" $topCtx }}
95         release: {{ $topCtx.Release.Name }}
96     spec:
97       hostname: {{ include "common.name.e2term" $topCtx }}-{{ $key }}
98       hostNetwork: {{ .hostnetworkmode }}
99       dnsPolicy: ClusterFirstWithHostNet
100       imagePullSecrets:
101         - name: {{ include "common.dockerregistry.credential" $imagectx }}
102       {{- with .nodeselector }}
103       nodeSelector: {{ toYaml . | trim | nindent 8 -}}
104       {{- end }}
105       containers:
106         - name: {{ include "common.containername.e2term" $topCtx }}
107           image: {{ include "common.dockerregistry.url" $imagectx }}/{{ .image.name }}:{{ .image.tag }}
108           imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $pullpolicyctx }}
109           volumeMounts:
110           - mountPath: /opt/e2/router.txt
111             name: local-router-file
112             subPath: router.txt
113           - mountPath: /tmp/rmr_verbose
114             name: local-router-file
115             subPath: rmr_verbose
116 {{ if .pizpub.enabled }}
117           - mountPath: "{{ .env.messagecollectorfile }}"
118             name: vol-shared
119             readOnly: false
120             subPath: "{{ .pizpub.scanDirectory }}"
121 {{ else }}
122           - mountPath: "{{ .env.messagecollectorfile }}"
123             name: vol-shared
124             readOnly: false
125 {{ end }}
126           envFrom:
127             - configMapRef:
128                 name: {{ include "common.configmapname.e2term" $topCtx }}-env-{{ $key }}
129           ports:
130             - name: "rmrroute-{{ $key }}"
131               containerPort: {{ include "common.serviceport.e2term.rmr.route" $topCtx }}
132             - name: "rmrdata-{{ $key }}"
133               containerPort: {{ include "common.serviceport.e2term.rmr.data" $topCtx }}
134             - name: "rmrsctp-{{ $key }}" 
135               containerPort: 36422
136               protocol: SCTP 
137           stdin: true
138           tty: true
139           securityContext:
140             privileged: {{ .privilegedmode }}
141           {{- if eq $health.liveness.enabled true }}
142           readinessProbe:
143             exec:
144               command: [ "/bin/sh", "-c", "{{ $health.readiness.command }}:{{ include "common.serviceport.e2term.rmr.data" . }}" ]
145             initialDelaySeconds: {{ $health.readiness.initialDelaySeconds }}
146             periodSeconds: {{ $health.readiness.periodSeconds }}
147           {{- end }}
148           {{- if eq $health.liveness.enabled true }}
149           livenessProbe:
150             exec:
151               command: [ "/bin/sh", "-c", "{{ $health.liveness.command }}:{{ include "common.serviceport.e2term.rmr.data" . }}" ]
152             initialDelaySeconds: {{ $health.liveness.initialDelaySeconds }}
153             periodSeconds: {{ $health.liveness.periodSeconds }}
154           {{- end }}
155 {{ if .pizpub.enabled }}
156         - name: {{ include "common.containername.e2term" $topCtx }}-pizpub
157           {{- $pizpubimagectx := dict "ctx" $topCtx "defaultregistry" .pizpub.image.registry }}
158           image: {{ include "common.dockerregistry.url" $pizpubimagectx }}/{{ .pizpub.image.name }}:{{ .pizpub.image.tag }}
159           imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $pullpolicyctx }}
160           volumeMounts:
161           - mountPath: /etc/localtime
162             name: localtime
163             readOnly: true
164           - mountPath: "{{ .pizpub.dataRootDir }}"
165             name: vol-shared
166             readOnly: false
167           - name: pizpub-config
168             mountPath: /opt/app/config/conf/
169           lifecycle:
170             postStart:
171               exec:
172                 command: ["/bin/sh", "/opt/app/config/conf/cleaner.sh", "{{ .pizpub.dataRootDir }}/{{ .pizpub.processedDirectory }}", "3"]
173 {{ end }}
174       volumes:
175         - name: local-router-file
176           configMap:
177             name: {{ include "common.configmapname.e2term" $topCtx }}-router-configmap
178 {{ if .pizpub.enabled }}
179         - name: localtime
180           hostPath:
181             path: /etc/localtime
182         - name: pizpub-config
183           configMap:
184             name: {{ include "common.configmapname.e2term" $topCtx }}-pizpub-{{ $key }}
185 {{ end }}
186         - name: vol-shared
187           persistentVolumeClaim:
188             claimName: {{ include "common.pvcname.e2term" $topCtx }}-{{ $key }}
189
190 {{- end }}
191 {{- end }}