blob: db587268935d56b36b6b9edb2af37f1e4ef15e65 [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.
vv770de8c5c682021-04-15 12:21:36 -04005# Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
Jack Lucasd41dbdb2021-02-16 11:07:28 -05006# ================================================================================
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# ============LICENSE_END=========================================================
19*/}}
20{{/*
Jack Lucascbca57d2021-04-05 09:49:46 -040021For internal use only!
22
23dcaegen2-services-common._ms-specific-env-vars:
24This template generates a list of microservice-specific environment variables
25as specified in .Values.applicationEnv. The
26dcaegen2-services-common.microServiceDeployment uses this template
27to add the microservice-specific environment variables to the microservice's container.
28These environment variables are in addition to a standard set of environment variables
29provided to all microservices.
30
31The template expects a single argument, pointing to the caller's global context.
32
33Microservice-specific environment variables can be specified in two ways:
34 1. As literal string values.
35 2. As values that are sourced from a secret, identified by the secret's
36 uid and the key within the secret that provides the value.
37
38The following example shows an example of each type. The example assumes
39that a secret has been created using the OOM common secret mechanism, with
40a secret uid "example-secret" and a key called "password".
41
42applicationEnv:
43 APPLICATION_PASSWORD:
44 secretUid: example-secret
45 key: password
46 APPLICATION_EXAMPLE: "An example value"
47
48The example would set two environment variables on the microservice's container,
49one called "APPLICATION_PASSWORD" with the value set from the "password" key in
50the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
51the the literal string "An example value".
52*/}}
53{{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
54 {{- $global := . }}
55 {{- if .Values.applicationEnv }}
56 {{- range $envName, $envValue := .Values.applicationEnv }}
57 {{- if kindIs "string" $envValue }}
58- name: {{ $envName }}
59 value: {{ $envValue | quote }}
60 {{- else }}
61 {{ if or (not $envValue.secretUid) (not $envValue.key) }}
62 {{ fail (printf "Env %s definition is not a string and does not contain secretUid or key fields" $envName) }}
63 {{- end }}
64- name: {{ $envName }}
65 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
66 {{- end -}}
67 {{- end }}
68 {{- end }}
69{{- end -}}
70{{/*
Jack Lucasd41dbdb2021-02-16 11:07:28 -050071dcaegen2-services-common.microserviceDeployment:
72This template produces a Kubernetes Deployment for a DCAE microservice.
73
74All DCAE microservices currently use very similar Deployments. Having a
75common template eliminates a lot of repetition in the individual charts
76for each microservice.
77
78The template expects the full chart context as input. A chart for a
79DCAE microservice references this template using:
80{{ include "dcaegen2-services-common.microserviceDeployment" . }}
81The template directly references data in .Values, and indirectly (through its
82use of templates from the ONAP "common" collection) references data in
83.Release.
84
85The exact content of the Deployment generated from this template
86depends on the content of .Values.
87
88The Deployment always includes a single Pod, with a container that uses
89the DCAE microservice image.
90
91The Deployment Pod may also include a logging sidecar container.
92The sidecar is included if .Values.logDirectory is set. The
93logging sidecar and the DCAE microservice container share a
94volume where the microservice logs are written.
95
96The Deployment includes an initContainer that pushes the
97microservice's initial configuration (from .Values.applicationConfig)
98into Consul. All DCAE microservices retrieve their initial
99configurations by making an API call to a DCAE platform component called
100the config-binding-service. The config-binding-service currently
101retrieves configuration information from Consul.
102
103The Deployment also includes an initContainer that checks for the
104readiness of other components that the microservice relies on.
105This container is generated by the "common.readinessCheck.waitfor"
106template.
107
108If the microservice acts as a TLS client or server, the Deployment will
109include an initContainer that retrieves certificate information from
110the AAF certificate manager. The information is mounted at the
111mount point specified in .Values.certDirectory. If the microservice is
112a TLS server (indicated by setting .Values.tlsServer to true), the
113certificate information will include a server cert and key, in various
114formats. It will also include the AAF CA cert. If the microservice is
115a TLS client only (indicated by setting .Values.tlsServer to false), the
116certificate information includes only the AAF CA cert.
vv770de8c5c682021-04-15 12:21:36 -0400117
118Deployed POD may also include a Policy-sync sidecar container.
119The sidecar is included if .Values.policies is set. The
120Policy-sync sidecar polls PolicyEngine (PDP) periodically based
121on .Values.policies.duration and configuration retrieved is shared with
122DCAE Microservice container by common volume. Policy can be retrieved based on
123list of policyID or filter
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500124*/}}
125
126{{- define "dcaegen2-services-common.microserviceDeployment" -}}
127{{- $logDir := default "" .Values.logDirectory -}}
128{{- $certDir := default "" .Values.certDirectory . -}}
129{{- $tlsServer := default "" .Values.tlsServer -}}
vv770de8c5c682021-04-15 12:21:36 -0400130{{- $policy := default "" .Values.policies -}}
131
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500132apiVersion: apps/v1
133kind: Deployment
134metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
135spec:
136 replicas: 1
137 selector: {{- include "common.selectors" . | nindent 4 }}
138 template:
139 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
140 spec:
141 initContainers:
142 - command:
143 - sh
144 args:
145 - -c
146 - |
147 {{- range $var := .Values.customEnvVars }}
148 export {{ $var.name }}="{{ $var.value }}";
149 {{- end }}
150 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
151 env:
152 {{- range $cred := .Values.credentials }}
153 - name: {{ $cred.name }}
154 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
155 {{- end }}
156 volumeMounts:
157 - mountPath: /config-input
158 name: app-config-input
159 - mountPath: /config
160 name: app-config
161 image: {{ include "repositoryGenerator.image.envsubst" . }}
162 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
163 name: {{ include "common.name" . }}-update-config
164
165 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
166 - name: init-consul
167 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
168 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
169 args:
170 - --key-yaml
171 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
172 resources: {{ include "common.resources" . | nindent 2 }}
173 volumeMounts:
174 - mountPath: /app-config
175 name: app-config
176 {{- if $certDir }}
177 - name: init-tls
178 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
179 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
180 env:
181 - name: TLS_SERVER
182 value: {{ $tlsServer | quote }}
183 - name: POD_IP
184 valueFrom:
185 fieldRef:
186 apiVersion: v1
187 fieldPath: status.podIP
188 resources: {{ include "common.resources" . | nindent 2 }}
189 volumeMounts:
190 - mountPath: /opt/app/osaaf
191 name: tls-info
192 {{- end }}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200193 {{ include "dcaegen2-services-common._certPostProcessor" . | nindent 4 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500194 containers:
195 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
196 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
197 name: {{ include "common.name" . }}
198 env:
199 {{- if $certDir }}
200 - name: DCAE_CA_CERTPATH
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200201 value: {{ $certDir }}/cacert.pem
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500202 {{- end }}
203 - name: CONSUL_HOST
204 value: consul-server.onap
205 - name: CONFIG_BINDING_SERVICE
206 value: config-binding-service
207 - name: CBS_CONFIG_URL
208 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
209 - name: POD_IP
210 valueFrom:
211 fieldRef:
212 apiVersion: v1
213 fieldPath: status.podIP
Jack Lucascbca57d2021-04-05 09:49:46 -0400214 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500215 {{- if .Values.service }}
216 ports: {{ include "common.containerPorts" . | nindent 10 }}
217 {{- end }}
218 {{- if .Values.readiness }}
219 readinessProbe:
220 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
221 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
222 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
223 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
224 {{- if eq $probeType "httpGet" }}
225 httpGet:
226 scheme: {{ .Values.readiness.scheme }}
227 path: {{ .Values.readiness.path }}
228 port: {{ .Values.readiness.port }}
229 {{- end }}
230 {{- if eq $probeType "exec" }}
231 exec:
232 command:
233 {{- range $cmd := .Values.readiness.command }}
234 - {{ $cmd }}
235 {{- end }}
236 {{- end }}
237 {{- end }}
238 resources: {{ include "common.resources" . | nindent 2 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500239 volumeMounts:
Bartosz Gardziejewski4bb3da32021-04-21 12:08:50 +0200240 - mountPath: /app-config
241 name: app-config
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500242 {{- if $logDir }}
243 - mountPath: {{ $logDir}}
244 name: component-log
245 {{- end }}
246 {{- if $certDir }}
247 - mountPath: {{ $certDir }}
248 name: tls-info
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200249 {{- if and .Values.certificates .Values.global.cmpv2Enabled .Values.global.CMPv2CertManagerIntegration -}}
250 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 8 -}}
251 {{- end -}}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500252 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400253 {{- if $policy }}
254 - name: policy-shared
255 mountPath: /etc/policies
256 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500257 {{- if $logDir }}
258 - image: {{ include "repositoryGenerator.image.logging" . }}
259 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
260 name: filebeat
261 env:
262 - name: POD_IP
263 valueFrom:
264 fieldRef:
265 apiVersion: v1
266 fieldPath: status.podIP
267 resources: {{ include "common.resources" . | nindent 2 }}
268 volumeMounts:
269 - mountPath: /var/log/onap/{{ include "common.name" . }}
270 name: component-log
271 - mountPath: /usr/share/filebeat/data
272 name: filebeat-data
273 - mountPath: /usr/share/filebeat/filebeat.yml
274 name: filebeat-conf
275 subPath: filebeat.yml
276 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400277 {{- if $policy }}
278 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
279 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
280 name: policy-sync
281 env:
282 - name: POD_IP
283 valueFrom:
284 fieldRef:
285 apiVersion: v1
286 fieldPath: status.podIP
287 - name: POLICY_SYNC_PDP_USER
288 valueFrom:
289 secretKeyRef:
290 name: onap-policy-xacml-pdp-api-creds
291 key: login
292 - name: POLICY_SYNC_PDP_PASS
293 valueFrom:
294 secretKeyRef:
295 name: onap-policy-xacml-pdp-api-creds
296 key: password
297 - name: POLICY_SYNC_PDP_URL
298 value : http{{ if (include "common.needTLS" .) }}s{{ end }}://policy-xacml-pdp:6969
299 - name: POLICY_SYNC_OUTFILE
300 value : "/etc/policies/policies.json"
301 - name: POLICY_SYNC_V1_DECISION_ENDPOINT
302 value : "policy/pdpx/v1/decision"
303 {{- if $policy.filter }}
304 - name: POLICY_SYNC_FILTER
305 value: {{ $policy.filter }}
306 {{- end -}}
307 {{- if $policy.policyID }}
308 - name: POLICY_SYNC_ID
309 value: {{ $policy.policyID }}
310 {{- end -}}
311 {{- if $policy.duration }}
312 - name: POLICY_SYNC_DURATION
313 value: {{ $policy.duration }}
314 {{- end }}
315 resources: {{ include "common.resources" . | nindent 2 }}
316 volumeMounts:
317 - mountPath: /etc/policies
318 name: policy-shared
319 {{- if $certDir }}
320 - mountPath: /opt/ca-certificates/
321 name: tls-info
322 {{- end }}
323 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500324 hostname: {{ include "common.name" . }}
325 volumes:
326 - configMap:
327 defaultMode: 420
328 name: {{ include "common.fullname" . }}-application-config-configmap
329 name: app-config-input
330 - emptyDir:
331 medium: Memory
332 name: app-config
333 {{- if $logDir }}
334 - emptyDir: {}
335 name: component-log
336 - emptyDir: {}
337 name: filebeat-data
338 - configMap:
339 defaultMode: 420
340 name: {{ include "common.fullname" . }}-filebeat-configmap
341 name: filebeat-conf
342 {{- end }}
343 {{- if $certDir }}
344 - emptyDir: {}
345 name: tls-info
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200346 {{ if and .Values.certificates .Values.global.cmpv2Enabled .Values.global.CMPv2CertManagerIntegration -}}
347 {{ include "common.certManager.volumesReadOnly" . | nindent 6 }}
348 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500349 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400350 {{- if $policy }}
351 - name: policy-shared
352 emptyDir: {}
353 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500354 imagePullSecrets:
355 - name: "{{ include "common.namespace" . }}-docker-registry-key"
356{{ end -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200357
358{{/*
359 For internal use
360
361 Template to attach CertPostProcessor which merges CMPv2 truststore with AAF truststore
362 and swaps keystore files.
363*/}}
364{{- define "dcaegen2-services-common._certPostProcessor" -}}
365 {{- $certDir := default "" .Values.certDirectory . -}}
366 {{- if and $certDir .Values.certificates .Values.global.cmpv2Enabled .Values.global.CMPv2CertManagerIntegration -}}
367 {{- $cmpv2Certificate := (index .Values.certificates 0) -}}
368 {{- $cmpv2CertificateDir := $cmpv2Certificate.mountPath -}}
369 {{- $certType := "pem" -}}
370 {{- if $cmpv2Certificate.keystore -}}
371 {{- $certType = (index $cmpv2Certificate.keystore.outputType 0) -}}
372 {{- end -}}
373 {{- $truststoresPaths := printf "%s/%s:%s/%s" $certDir "cacert.pem" $cmpv2CertificateDir "ca.crt" -}}
374 {{- $truststoresPasswordPaths := "" -}}
375 {{- $keystoreSourcePaths := printf "%s/%s:%s/%s" $cmpv2CertificateDir "tls.crt" $cmpv2CertificateDir "tls.key" -}}
376 {{- $keystoreDestinationPaths := printf "%s/%s:%s/%s" $certDir "cert.pem" $certDir "key.pem" -}}
377 {{- if not (eq $certType "pem") -}}
378 {{- $truststoresPaths = printf "%s/%s:%s/%s.%s" $certDir "trust.jks" $cmpv2CertificateDir "truststore" $certType -}}
379 {{- $truststoresPasswordPaths = printf "%s/%s:%s/%s" $certDir "trust.pass" $cmpv2CertificateDir "truststore.pass" -}}
380 {{- $keystoreSourcePaths = printf "%s/%s.%s:%s/%s" $cmpv2CertificateDir "keystore" $certType $cmpv2CertificateDir "keystore.pass" -}}
381 {{- $keystoreDestinationPaths = printf "%s/%s.%s:%s/%s.pass" $certDir "cert" $certType $certDir $certType -}}
382 {{- end }}
383 - name: cert-post-processor
384 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.certPostProcessorImage }}
385 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
386 resources:
387 {{- include "common.resources" . | nindent 4 }}
388 volumeMounts:
389 - mountPath: {{ $certDir }}
390 name: tls-info
391 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 4 }}
392 env:
393 - name: TRUSTSTORES_PATHS
394 value: {{ $truststoresPaths | quote}}
395 - name: TRUSTSTORES_PASSWORDS_PATHS
396 value: {{ $truststoresPasswordPaths | quote }}
397 - name: KEYSTORE_SOURCE_PATHS
398 value: {{ $keystoreSourcePaths | quote }}
399 - name: KEYSTORE_DESTINATION_PATHS
400 value: {{ $keystoreDestinationPaths | quote }}
401 {{- end }}
402{{- end -}}