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