2 #============LICENSE_START========================================================
3 # ================================================================================
4 # Copyright (c) 2021 J. F. Lucas. All rights reserved.
5 # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
6 # Copyright (c) 2021 Nokia. All rights reserved.
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 For internal use only!
24 dcaegen2-services-common._ms-specific-env-vars:
25 This template generates a list of microservice-specific environment variables
26 as specified in .Values.applicationEnv. The
27 dcaegen2-services-common.microServiceDeployment uses this template
28 to add the microservice-specific environment variables to the microservice's container.
29 These environment variables are in addition to a standard set of environment variables
30 provided to all microservices.
32 The template expects a single argument, pointing to the caller's global context.
34 Microservice-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.
39 The following example shows an example of each type. The example assumes
40 that a secret has been created using the OOM common secret mechanism, with
41 a secret uid "example-secret" and a key called "password".
45 secretUid: example-secret
47 APPLICATION_EXAMPLE: "An example value"
49 The example would set two environment variables on the microservice's container,
50 one called "APPLICATION_PASSWORD" with the value set from the "password" key in
51 the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
52 the the literal string "An example value".
54 {{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
56 {{- if .Values.applicationEnv }}
57 {{- range $envName, $envValue := .Values.applicationEnv }}
58 {{- if kindIs "string" $envValue }}
59 - name: {{ $envName }}
60 value: {{ $envValue | quote }}
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) }}
65 - name: {{ $envName }}
66 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
72 For internal use only!
74 dcaegen2-services-common._externalVolumes:
75 This template generates a list of volumes associated with the pod,
76 based on information provided in .Values.externalVolumes. This
77 template works in conjunction with dcaegen2-services-common._externalVolumeMounts
78 to give the microservice access to data in volumes created else.
79 This initial implementation supports ConfigMaps only, as this is the only
80 external volume mounting required by current microservices.
82 .Values.externalVolumes is a list of objects. Each object has 3 required fields and 2 optional fields:
83 - name: the name of the resource (in the current implementation, it must be a ConfigMap)
84 that is to be set up as a volume. The value is a case sensitive string. Because the
85 names of resources are sometimes set at deployment time (for instance, to prefix the Helm
86 release to the name), the string can be a Helm template fragment that will be expanded at
88 - type: the type of the resource (in the current implementation, only "ConfigMap" is supported).
89 The value is a case-INsensitive string.
90 - mountPoint: the path to the mount point for the volume in the container file system. The
91 value is a case-sensitive string.
92 - readOnly: (Optional) Boolean flag. Set to true to mount the volume as read-only.
94 - optional: (Optional) Boolean flag. Set to true to make the configMap optional (i.e., to allow the
95 microservice's pod to start even if the configMap doesn't exist). If set to false, the configMap must
96 be present in order for the microservice's pod to start. Defaults to true. (Note that this
97 default is the opposite of the Kubernetes default. We've done this to be consistent with the behavior
98 of the DCAE Cloudify plugin for Kubernetes [k8splugin], which always set "optional" to true.)
100 Here is an example fragment from a values.yaml file for a microservice:
103 - name: my-example-configmap
105 mountPath: /opt/app/config
106 - name: '{{ include "common.release" . }}-another-example'
108 mountPath: /opt/app/otherconfig
111 {{- define "dcaegen2-services-common._externalVolumes" -}}
113 {{- if .Values.externalVolumes }}
114 {{- range $vol := .Values.externalVolumes }}
115 {{- if eq (lower $vol.type) "configmap" }}
116 {{- $vname := (tpl $vol.name $global) -}}
117 {{- $opt := hasKey $vol "optional" | ternary $vol.optional true }}
128 For internal use only!
130 dcaegen2-services-common._externalVolumeMounts:
131 This template generates a list of volume mounts for the microservice container,
132 based on information provided in .Values.externalVolumes. This
133 template works in conjunction with dcaegen2-services-common._externalVolumes
134 to give the microservice access to data in volumes created else.
135 This initial implementation supports ConfigMaps only, as this is the only
136 external volume mounting required by current microservices.
138 See the documentation for dcaegen2-services-common._externalVolumes for
139 details on how external volumes are specified in the values.yaml file for
142 {{- define "dcaegen2-services-common._externalVolumeMounts" -}}
144 {{- if .Values.externalVolumes }}
145 {{- range $vol := .Values.externalVolumes }}
146 {{- if eq (lower $vol.type) "configmap" }}
147 {{- $vname := (tpl $vol.name $global) -}}
148 {{- $readOnly := $vol.readOnly | default false }}
149 - mountPath: {{ $vol.mountPath }}
151 readOnly: {{ $readOnly }}
157 dcaegen2-services-common.microserviceDeployment:
158 This template produces a Kubernetes Deployment for a DCAE microservice.
160 All DCAE microservices currently use very similar Deployments. Having a
161 common template eliminates a lot of repetition in the individual charts
162 for each microservice.
164 The template expects the full chart context as input. A chart for a
165 DCAE microservice references this template using:
166 {{ include "dcaegen2-services-common.microserviceDeployment" . }}
167 The template directly references data in .Values, and indirectly (through its
168 use of templates from the ONAP "common" collection) references data in
171 The exact content of the Deployment generated from this template
172 depends on the content of .Values.
174 The Deployment always includes a single Pod, with a container that uses
175 the DCAE microservice image.
177 The Deployment Pod may also include a logging sidecar container.
178 The sidecar is included if .Values.logDirectory is set. The
179 logging sidecar and the DCAE microservice container share a
180 volume where the microservice logs are written.
182 The Deployment includes an initContainer that pushes the
183 microservice's initial configuration (from .Values.applicationConfig)
184 into Consul. All DCAE microservices retrieve their initial
185 configurations by making an API call to a DCAE platform component called
186 the config-binding-service. The config-binding-service currently
187 retrieves configuration information from Consul.
189 The Deployment also includes an initContainer that checks for the
190 readiness of other components that the microservice relies on.
191 This container is generated by the "common.readinessCheck.waitfor"
194 If the microservice acts as a TLS client or server, the Deployment will
195 include an initContainer that retrieves certificate information from
196 the AAF certificate manager. The information is mounted at the
197 mount point specified in .Values.certDirectory. If the microservice is
198 a TLS server (indicated by setting .Values.tlsServer to true), the
199 certificate information will include a server cert and key, in various
200 formats. It will also include the AAF CA cert. If the microservice is
201 a TLS client only (indicated by setting .Values.tlsServer to false), the
202 certificate information includes only the AAF CA cert.
204 Deployed POD may also include a Policy-sync sidecar container.
205 The sidecar is included if .Values.policies is set. The
206 Policy-sync sidecar polls PolicyEngine (PDP) periodically based
207 on .Values.policies.duration and configuration retrieved is shared with
208 DCAE Microservice container by common volume. Policy can be retrieved based on
209 list of policyID or filter
212 {{- define "dcaegen2-services-common.microserviceDeployment" -}}
213 {{- $logDir := default "" .Values.logDirectory -}}
214 {{- $certDir := default "" .Values.certDirectory . -}}
215 {{- $tlsServer := default "" .Values.tlsServer -}}
216 {{- $policy := default "" .Values.policies -}}
220 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
223 selector: {{- include "common.selectors" . | nindent 4 }}
225 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
233 {{- range $var := .Values.customEnvVars }}
234 export {{ $var.name }}="{{ $var.value }}";
236 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
238 {{- range $cred := .Values.credentials }}
239 - name: {{ $cred.name }}
240 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
243 - mountPath: /config-input
244 name: app-config-input
247 image: {{ include "repositoryGenerator.image.envsubst" . }}
248 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
249 name: {{ include "common.name" . }}-update-config
251 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
253 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
254 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
257 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
258 resources: {{ include "common.resources" . | nindent 2 }}
260 - mountPath: /app-config
264 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
265 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
268 value: {{ $tlsServer | quote }}
273 fieldPath: status.podIP
274 resources: {{ include "common.resources" . | nindent 2 }}
276 - mountPath: /opt/app/osaaf
279 {{ include "dcaegen2-services-common._certPostProcessor" . | nindent 4 }}
281 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
282 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
283 name: {{ include "common.name" . }}
285 {{- range $cred := .Values.credentials }}
286 - name: {{ $cred.name }}
287 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
290 - name: DCAE_CA_CERTPATH
291 value: {{ $certDir }}/cacert.pem
294 value: consul-server.onap
295 - name: CONFIG_BINDING_SERVICE
296 value: config-binding-service
297 - name: CBS_CONFIG_URL
298 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
303 fieldPath: status.podIP
304 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
305 {{- if .Values.service }}
306 ports: {{ include "common.containerPorts" . | nindent 10 }}
308 {{- if .Values.readiness }}
310 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
311 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
312 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
313 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
314 {{- if eq $probeType "httpGet" }}
316 scheme: {{ .Values.readiness.scheme }}
317 path: {{ .Values.readiness.path }}
318 port: {{ .Values.readiness.port }}
320 {{- if eq $probeType "exec" }}
323 {{- range $cmd := .Values.readiness.command }}
328 resources: {{ include "common.resources" . | nindent 2 }}
330 - mountPath: /app-config
332 - mountPath: /app-config-input
333 name: app-config-input
335 - mountPath: {{ $logDir}}
339 - mountPath: {{ $certDir }}
341 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
342 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 8 -}}
346 - name: policy-shared
347 mountPath: /etc/policies
349 {{- include "dcaegen2-services-common._externalVolumeMounts" . | nindent 8 }}
351 - image: {{ include "repositoryGenerator.image.logging" . }}
352 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
359 fieldPath: status.podIP
360 resources: {{ include "common.resources" . | nindent 2 }}
362 - mountPath: /var/log/onap/{{ include "common.name" . }}
364 - mountPath: /usr/share/filebeat/data
366 - mountPath: /usr/share/filebeat/filebeat.yml
368 subPath: filebeat.yml
371 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
372 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
379 fieldPath: status.podIP
380 - name: POLICY_SYNC_PDP_USER
383 name: onap-policy-xacml-pdp-api-creds
385 - name: POLICY_SYNC_PDP_PASS
388 name: onap-policy-xacml-pdp-api-creds
390 - name: POLICY_SYNC_PDP_URL
391 value : http{{ if (include "common.needTLS" .) }}s{{ end }}://policy-xacml-pdp:6969
392 - name: POLICY_SYNC_OUTFILE
393 value : "/etc/policies/policies.json"
394 - name: POLICY_SYNC_V1_DECISION_ENDPOINT
395 value : "policy/pdpx/v1/decision"
396 {{- if $policy.filter }}
397 - name: POLICY_SYNC_FILTER
398 value: {{ $policy.filter }}
400 {{- if $policy.policyID }}
401 - name: POLICY_SYNC_ID
402 value: {{ $policy.policyID }}
404 {{- if $policy.duration }}
405 - name: POLICY_SYNC_DURATION
406 value: {{ $policy.duration }}
408 resources: {{ include "common.resources" . | nindent 2 }}
410 - mountPath: /etc/policies
413 - mountPath: /opt/ca-certificates/
417 hostname: {{ include "common.name" . }}
421 name: {{ include "common.fullname" . }}-application-config-configmap
422 name: app-config-input
433 name: {{ include "common.fullname" . }}-filebeat-configmap
439 {{ if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
440 {{ include "common.certManager.volumesReadOnly" . | nindent 6 }}
444 - name: policy-shared
447 {{- include "dcaegen2-services-common._externalVolumes" . | nindent 6 }}
449 - name: "{{ include "common.namespace" . }}-docker-registry-key"
455 Template to attach CertPostProcessor which merges CMPv2 truststore with AAF truststore
456 and swaps keystore files.
458 {{- define "dcaegen2-services-common._certPostProcessor" -}}
459 {{- $certDir := default "" .Values.certDirectory . -}}
460 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
461 {{- $cmpv2Certificate := (index .Values.certificates 0) -}}
462 {{- $cmpv2CertificateDir := $cmpv2Certificate.mountPath -}}
463 {{- $certType := "pem" -}}
464 {{- if $cmpv2Certificate.keystore -}}
465 {{- $certType = (index $cmpv2Certificate.keystore.outputType 0) -}}
467 {{- $truststoresPaths := printf "%s/%s:%s/%s" $certDir "cacert.pem" $cmpv2CertificateDir "cacert.pem" -}}
468 {{- $truststoresPasswordPaths := ":" -}}
469 {{- $keystoreSourcePaths := printf "%s/%s:%s/%s" $cmpv2CertificateDir "cert.pem" $cmpv2CertificateDir "key.pem" -}}
470 {{- $keystoreDestinationPaths := printf "%s/%s:%s/%s" $certDir "cert.pem" $certDir "key.pem" -}}
471 {{- if not (eq $certType "pem") -}}
472 {{- $truststoresPaths = printf "%s/%s:%s/%s.%s" $certDir "trust.jks" $cmpv2CertificateDir "truststore" $certType -}}
473 {{- $truststoresPasswordPaths = printf "%s/%s:%s/%s" $certDir "trust.pass" $cmpv2CertificateDir "truststore.pass" -}}
474 {{- $keystoreSourcePaths = printf "%s/%s.%s:%s/%s" $cmpv2CertificateDir "keystore" $certType $cmpv2CertificateDir "keystore.pass" -}}
475 {{- $keystoreDestinationPaths = printf "%s/%s.%s:%s/%s.pass" $certDir "cert" $certType $certDir $certType -}}
477 - name: cert-post-processor
478 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.certPostProcessorImage }}
479 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
481 {{- include "common.resources" . | nindent 4 }}
483 - mountPath: {{ $certDir }}
485 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 4 }}
487 - name: TRUSTSTORES_PATHS
488 value: {{ $truststoresPaths | quote}}
489 - name: TRUSTSTORES_PASSWORDS_PATHS
490 value: {{ $truststoresPasswordPaths | quote }}
491 - name: KEYSTORE_SOURCE_PATHS
492 value: {{ $keystoreSourcePaths | quote }}
493 - name: KEYSTORE_DESTINATION_PATHS
494 value: {{ $keystoreDestinationPaths | quote }}
499 Template returns string "true" if CMPv2 certificates should be used and nothing (so it can be used in with statements)
500 when they shouldn't. Example use:
501 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
504 {{- define "dcaegen2-services-common.shouldUseCmpv2Certificates" -}}
505 {{- $certDir := default "" .Values.certDirectory . -}}
506 {{- if (and $certDir .Values.certificates .Values.global.cmpv2Enabled .Values.useCmpv2Certificates) -}}