blob: e9ada4d87cc463722f0ab9b442ff14403bb3a9e5 [file] [log] [blame]
Jack Lucasd41dbdb2021-02-16 11:07:28 -05001{{/*
2#============LICENSE_START========================================================
3# ================================================================================
4# Copyright (c) 2021 J. F. Lucas. All rights reserved.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=========================================================
18*/}}
19{{/*
20dcaegen2-services-common.microserviceDeployment:
21This template produces a Kubernetes Deployment for a DCAE microservice.
22
23All DCAE microservices currently use very similar Deployments. Having a
24common template eliminates a lot of repetition in the individual charts
25for each microservice.
26
27The template expects the full chart context as input. A chart for a
28DCAE microservice references this template using:
29{{ include "dcaegen2-services-common.microserviceDeployment" . }}
30The template directly references data in .Values, and indirectly (through its
31use of templates from the ONAP "common" collection) references data in
32.Release.
33
34The exact content of the Deployment generated from this template
35depends on the content of .Values.
36
37The Deployment always includes a single Pod, with a container that uses
38the DCAE microservice image.
39
40The Deployment Pod may also include a logging sidecar container.
41The sidecar is included if .Values.logDirectory is set. The
42logging sidecar and the DCAE microservice container share a
43volume where the microservice logs are written.
44
45The Deployment includes an initContainer that pushes the
46microservice's initial configuration (from .Values.applicationConfig)
47into Consul. All DCAE microservices retrieve their initial
48configurations by making an API call to a DCAE platform component called
49the config-binding-service. The config-binding-service currently
50retrieves configuration information from Consul.
51
52The Deployment also includes an initContainer that checks for the
53readiness of other components that the microservice relies on.
54This container is generated by the "common.readinessCheck.waitfor"
55template.
56
57If the microservice acts as a TLS client or server, the Deployment will
58include an initContainer that retrieves certificate information from
59the AAF certificate manager. The information is mounted at the
60mount point specified in .Values.certDirectory. If the microservice is
61a TLS server (indicated by setting .Values.tlsServer to true), the
62certificate information will include a server cert and key, in various
63formats. It will also include the AAF CA cert. If the microservice is
64a TLS client only (indicated by setting .Values.tlsServer to false), the
65certificate information includes only the AAF CA cert.
66*/}}
67
68{{- define "dcaegen2-services-common.microserviceDeployment" -}}
69{{- $logDir := default "" .Values.logDirectory -}}
70{{- $certDir := default "" .Values.certDirectory . -}}
71{{- $tlsServer := default "" .Values.tlsServer -}}
72apiVersion: apps/v1
73kind: Deployment
74metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
75spec:
76 replicas: 1
77 selector: {{- include "common.selectors" . | nindent 4 }}
78 template:
79 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
80 spec:
81 initContainers:
82 - command:
83 - sh
84 args:
85 - -c
86 - |
87 {{- range $var := .Values.customEnvVars }}
88 export {{ $var.name }}="{{ $var.value }}";
89 {{- end }}
90 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
91 env:
92 {{- range $cred := .Values.credentials }}
93 - name: {{ $cred.name }}
94 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
95 {{- end }}
96 volumeMounts:
97 - mountPath: /config-input
98 name: app-config-input
99 - mountPath: /config
100 name: app-config
101 image: {{ include "repositoryGenerator.image.envsubst" . }}
102 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
103 name: {{ include "common.name" . }}-update-config
104
105 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
106 - name: init-consul
107 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
108 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
109 args:
110 - --key-yaml
111 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
112 resources: {{ include "common.resources" . | nindent 2 }}
113 volumeMounts:
114 - mountPath: /app-config
115 name: app-config
116 {{- if $certDir }}
117 - name: init-tls
118 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
119 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
120 env:
121 - name: TLS_SERVER
122 value: {{ $tlsServer | quote }}
123 - name: POD_IP
124 valueFrom:
125 fieldRef:
126 apiVersion: v1
127 fieldPath: status.podIP
128 resources: {{ include "common.resources" . | nindent 2 }}
129 volumeMounts:
130 - mountPath: /opt/app/osaaf
131 name: tls-info
132 {{- end }}
133 containers:
134 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
135 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
136 name: {{ include "common.name" . }}
137 env:
138 {{- if $certDir }}
139 - name: DCAE_CA_CERTPATH
140 value: {{ $certDir}}/cacert.pem
141 {{- end }}
142 - name: CONSUL_HOST
143 value: consul-server.onap
144 - name: CONFIG_BINDING_SERVICE
145 value: config-binding-service
146 - name: CBS_CONFIG_URL
147 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
148 - name: POD_IP
149 valueFrom:
150 fieldRef:
151 apiVersion: v1
152 fieldPath: status.podIP
153 {{- if .Values.applicationEnv }}
154 {{- range $envName, $envValue := .Values.applicationEnv }}
155 - name: {{ $envName }}
156 value: {{ $envValue | quote }}
157 {{- end }}
158 {{- end }}
159 {{- if .Values.service }}
160 ports: {{ include "common.containerPorts" . | nindent 10 }}
161 {{- end }}
162 {{- if .Values.readiness }}
163 readinessProbe:
164 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
165 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
166 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
167 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
168 {{- if eq $probeType "httpGet" }}
169 httpGet:
170 scheme: {{ .Values.readiness.scheme }}
171 path: {{ .Values.readiness.path }}
172 port: {{ .Values.readiness.port }}
173 {{- end }}
174 {{- if eq $probeType "exec" }}
175 exec:
176 command:
177 {{- range $cmd := .Values.readiness.command }}
178 - {{ $cmd }}
179 {{- end }}
180 {{- end }}
181 {{- end }}
182 resources: {{ include "common.resources" . | nindent 2 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500183 volumeMounts:
Bartosz Gardziejewski4bb3da32021-04-21 12:08:50 +0200184 - mountPath: /app-config
185 name: app-config
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500186 {{- if $logDir }}
187 - mountPath: {{ $logDir}}
188 name: component-log
189 {{- end }}
190 {{- if $certDir }}
191 - mountPath: {{ $certDir }}
192 name: tls-info
193 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500194 {{- if $logDir }}
195 - image: {{ include "repositoryGenerator.image.logging" . }}
196 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
197 name: filebeat
198 env:
199 - name: POD_IP
200 valueFrom:
201 fieldRef:
202 apiVersion: v1
203 fieldPath: status.podIP
204 resources: {{ include "common.resources" . | nindent 2 }}
205 volumeMounts:
206 - mountPath: /var/log/onap/{{ include "common.name" . }}
207 name: component-log
208 - mountPath: /usr/share/filebeat/data
209 name: filebeat-data
210 - mountPath: /usr/share/filebeat/filebeat.yml
211 name: filebeat-conf
212 subPath: filebeat.yml
213 {{- end }}
214 hostname: {{ include "common.name" . }}
215 volumes:
216 - configMap:
217 defaultMode: 420
218 name: {{ include "common.fullname" . }}-application-config-configmap
219 name: app-config-input
220 - emptyDir:
221 medium: Memory
222 name: app-config
223 {{- if $logDir }}
224 - emptyDir: {}
225 name: component-log
226 - emptyDir: {}
227 name: filebeat-data
228 - configMap:
229 defaultMode: 420
230 name: {{ include "common.fullname" . }}-filebeat-configmap
231 name: filebeat-conf
232 {{- end }}
233 {{- if $certDir }}
234 - emptyDir: {}
235 name: tls-info
236 {{- end }}
237 imagePullSecrets:
238 - name: "{{ include "common.namespace" . }}-docker-registry-key"
239{{ end -}}