2 #============LICENSE_START========================================================
3 # ================================================================================
4 # Copyright (c) 2021-2022 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 # Copyright (c) 2021 Nordix Foundation.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END=========================================================
23 For internal use only!
25 dcaegen2-services-common._ms-specific-env-vars:
26 This template generates a list of microservice-specific environment variables
27 as specified in .Values.applicationEnv. The
28 dcaegen2-services-common.microServiceDeployment uses this template
29 to add the microservice-specific environment variables to the microservice's container.
30 These environment variables are in addition to a standard set of environment variables
31 provided to all microservices.
33 The template expects a single argument, pointing to the caller's global context.
35 Microservice-specific environment variables can be specified in two ways:
36 1. As literal string values.
37 2. As values that are sourced from a secret, identified by the secret's
38 uid and the key within the secret that provides the value.
40 The following example shows an example of each type. The example assumes
41 that a secret has been created using the OOM common secret mechanism, with
42 a secret uid "example-secret" and a key called "password".
46 secretUid: example-secret
48 APPLICATION_EXAMPLE: "An example value"
50 The example would set two environment variables on the microservice's container,
51 one called "APPLICATION_PASSWORD" with the value set from the "password" key in
52 the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
53 the the literal string "An example value".
55 {{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
57 {{- if .Values.applicationEnv }}
58 {{- range $envName, $envValue := .Values.applicationEnv }}
59 {{- if kindIs "string" $envValue }}
60 - name: {{ $envName }}
61 value: {{ $envValue | quote }}
63 {{ if or (not $envValue.secretUid) (not $envValue.key) }}
64 {{ fail (printf "Env %s definition is not a string and does not contain secretUid or key fields" $envName) }}
66 - name: {{ $envName }}
67 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
73 For internal use only!
75 dcaegen2-services-common._externalVolumes:
76 This template generates a list of volumes associated with the pod,
77 based on information provided in .Values.externalVolumes. This
78 template works in conjunction with dcaegen2-services-common._externalVolumeMounts
79 to give the microservice access to data in volumes created else.
80 This initial implementation supports ConfigMaps only, as this is the only
81 external volume mounting required by current microservices.
83 .Values.externalVolumes is a list of objects. Each object has 3 required fields and 2 optional fields:
84 - name: the name of the resource (in the current implementation, it must be a ConfigMap)
85 that is to be set up as a volume. The value is a case sensitive string. Because the
86 names of resources are sometimes set at deployment time (for instance, to prefix the Helm
87 release to the name), the string can be a Helm template fragment that will be expanded at
89 - type: the type of the resource (in the current implementation, only "ConfigMap" is supported).
90 The value is a case-INsensitive string.
91 - mountPoint: the path to the mount point for the volume in the container file system. The
92 value is a case-sensitive string.
93 - readOnly: (Optional) Boolean flag. Set to true to mount the volume as read-only.
95 - optional: (Optional) Boolean flag. Set to true to make the configMap optional (i.e., to allow the
96 microservice's pod to start even if the configMap doesn't exist). If set to false, the configMap must
97 be present in order for the microservice's pod to start. Defaults to true. (Note that this
98 default is the opposite of the Kubernetes default. We've done this to be consistent with the behavior
99 of the DCAE Cloudify plugin for Kubernetes [k8splugin], which always set "optional" to true.)
101 Here is an example fragment from a values.yaml file for a microservice:
104 - name: my-example-configmap
106 mountPath: /opt/app/config
107 - name: '{{ include "common.release" . }}-another-example'
109 mountPath: /opt/app/otherconfig
112 {{- define "dcaegen2-services-common._externalVolumes" -}}
114 {{- if .Values.externalVolumes }}
115 {{- range $vol := .Values.externalVolumes }}
116 {{- if eq (lower $vol.type) "configmap" }}
117 {{- $vname := (tpl $vol.name $global) -}}
118 {{- $opt := hasKey $vol "optional" | ternary $vol.optional true }}
129 For internal use only!
131 dcaegen2-services-common._externalVolumeMounts:
132 This template generates a list of volume mounts for the microservice container,
133 based on information provided in .Values.externalVolumes. This
134 template works in conjunction with dcaegen2-services-common._externalVolumes
135 to give the microservice access to data in volumes created else.
136 This initial implementation supports ConfigMaps only, as this is the only
137 external volume mounting required by current microservices.
139 See the documentation for dcaegen2-services-common._externalVolumes for
140 details on how external volumes are specified in the values.yaml file for
143 {{- define "dcaegen2-services-common._externalVolumeMounts" -}}
145 {{- if .Values.externalVolumes }}
146 {{- range $vol := .Values.externalVolumes }}
147 {{- if eq (lower $vol.type) "configmap" }}
148 {{- $vname := (tpl $vol.name $global) -}}
149 {{- $readOnly := $vol.readOnly | default false }}
150 - mountPath: {{ $vol.mountPath }}
152 readOnly: {{ $readOnly }}
158 dcaegen2-services-common.microserviceDeployment:
159 This template produces a Kubernetes Deployment for a DCAE microservice.
161 All DCAE microservices currently use very similar Deployments. Having a
162 common template eliminates a lot of repetition in the individual charts
163 for each microservice.
165 The template expects the full chart context as input. A chart for a
166 DCAE microservice references this template using:
167 {{ include "dcaegen2-services-common.microserviceDeployment" . }}
168 The template directly references data in .Values, and indirectly (through its
169 use of templates from the ONAP "common" collection) references data in
172 The exact content of the Deployment generated from this template
173 depends on the content of .Values.
175 The Deployment always includes a single Pod, with a container that uses
176 the DCAE microservice image.
178 The Deployment Pod may also include a logging sidecar container.
179 The sidecar is included if .Values.log.path is set. The
180 logging sidecar and the DCAE microservice container share a
181 volume where the microservice logs are written.
183 The Deployment includes an initContainer that checks for the
184 readiness of other components that the microservice relies on.
185 This container is generated by the "common.readinessCheck.waitfor"
188 If the microservice acts as a TLS client or server, the Deployment will
189 include an initContainer that retrieves certificate information from
190 the AAF certificate manager. The information is mounted at the
191 mount point specified in .Values.certDirectory. If the microservice is
192 a TLS server (indicated by setting .Values.tlsServer to true), the
193 certificate information will include a server cert and key, in various
194 formats. It will also include the AAF CA cert. If the microservice is
195 a TLS client only (indicated by setting .Values.tlsServer to false), the
196 certificate information includes only the AAF CA cert.
198 Deployed POD may also include a Policy-sync sidecar container.
199 The sidecar is included if .Values.policies is set. The
200 Policy-sync sidecar polls PolicyEngine (PDP) periodically based
201 on .Values.policies.duration and configuration retrieved is shared with
202 DCAE Microservice container by common volume. Policy can be retrieved based on
203 list of policyID or filter. An optional policyRelease parameter can be specified
204 to override the default policy helm release (used for retreiving the secret containing
205 pdp username and password)
207 Following is example policy config override
209 dcaePolicySyncImage: onap/org.onap.dcaegen2.deployments.dcae-services-policy-sync:1.0.1
212 policyRelease: "onap"
214 '["onap.vfirewall.tca","onap.vdns.tca"]'
217 {{- define "dcaegen2-services-common.microserviceDeployment" -}}
218 {{- $log := default dict .Values.log -}}
219 {{- $logDir := default "" $log.path -}}
220 {{- $certDir := default "" .Values.certDirectory . -}}
221 {{- $tlsServer := default "" .Values.tlsServer -}}
222 {{- $commonRelease := print (include "common.release" .) -}}
223 {{- $policy := default dict .Values.policies -}}
224 {{- $policyRls := default $commonRelease $policy.policyRelease -}}
225 {{- $drFeedConfig := default "" .Values.drFeedConfig -}}
226 {{- $dcaeName := print (include "common.fullname" .) }}
227 {{- $dcaeLabel := (dict "dcaeMicroserviceName" $dcaeName) -}}
231 metadata: {{- include "common.resourceMetadata" (dict "dot" $dot "labels" $dcaeLabel) | nindent 2 }}
234 selector: {{- include "common.selectors" . | nindent 4 }}
236 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
239 {{- if not $drFeedConfig }}
245 {{- range $var := .Values.customEnvVars }}
246 export {{ $var.name }}="{{ $var.value }}";
248 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
250 {{- range $cred := .Values.credentials }}
251 - name: {{ $cred.name }}
252 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
255 - mountPath: /config-input
256 name: app-config-input
259 image: {{ include "repositoryGenerator.image.envsubst" . }}
260 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
261 name: {{ include "common.name" . }}-update-config
263 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
264 {{- include "common.dmaap.provisioning.initContainer" . | nindent 6 }}
267 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
268 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
271 value: {{ $tlsServer | quote }}
276 fieldPath: status.podIP
277 resources: {{ include "common.resources" . | nindent 2 }}
279 - mountPath: /opt/app/osaaf
282 {{ include "dcaegen2-services-common._certPostProcessor" . | nindent 4 }}
284 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
285 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
286 name: {{ include "common.name" . }}
288 {{- range $cred := .Values.credentials }}
289 - name: {{ $cred.name }}
290 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
293 - name: DCAE_CA_CERTPATH
294 value: {{ $certDir }}/cacert.pem
297 value: consul-server.onap
298 - name: CONFIG_BINDING_SERVICE
299 value: config-binding-service
300 - name: CBS_CONFIG_URL
301 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
306 fieldPath: status.podIP
307 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
308 {{- if .Values.service }}
309 ports: {{ include "common.containerPorts" . | nindent 10 }}
311 {{- if .Values.readiness }}
313 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
314 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
315 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
316 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
317 {{- if eq $probeType "httpGet" }}
319 scheme: {{ .Values.readiness.scheme }}
320 path: {{ .Values.readiness.path }}
321 port: {{ .Values.readiness.port }}
323 {{- if eq $probeType "exec" }}
326 {{- range $cmd := .Values.readiness.command }}
331 resources: {{ include "common.resources" . | nindent 2 }}
333 - mountPath: /app-config
335 - mountPath: /app-config-input
336 name: app-config-input
338 - mountPath: {{ $logDir}}
342 - mountPath: {{ $certDir }}
344 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
345 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 8 -}}
349 - name: policy-shared
350 mountPath: /etc/policies
352 {{- include "dcaegen2-services-common._externalVolumeMounts" . | nindent 8 }}
354 {{ include "common.log.sidecar" . | nindent 6 }}
357 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
358 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
365 fieldPath: status.podIP
366 - name: POLICY_SYNC_PDP_USER
369 name: {{ $policyRls }}-policy-xacml-pdp-api-creds
371 - name: POLICY_SYNC_PDP_PASS
374 name: {{ $policyRls }}-policy-xacml-pdp-api-creds
376 - name: POLICY_SYNC_PDP_URL
377 value : http{{ if (include "common.needTLS" .) }}s{{ end }}://policy-xacml-pdp:6969
378 - name: POLICY_SYNC_OUTFILE
379 value : "/etc/policies/policies.json"
380 - name: POLICY_SYNC_V1_DECISION_ENDPOINT
381 value : "policy/pdpx/v1/decision"
382 {{- if $policy.filter }}
383 - name: POLICY_SYNC_FILTER
384 value: {{ $policy.filter }}
386 {{- if $policy.policyID }}
387 - name: POLICY_SYNC_ID
388 value: {{ $policy.policyID }}
390 {{- if $policy.duration }}
391 - name: POLICY_SYNC_DURATION
392 value: "{{ $policy.duration }}"
394 resources: {{ include "common.resources" . | nindent 2 }}
396 - mountPath: /etc/policies
399 - mountPath: /opt/ca-certificates/
403 hostname: {{ include "common.name" . }}
404 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
408 name: {{ include "common.fullname" . }}-application-config-configmap
409 name: app-config-input
416 {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix . )) | nindent 6 }}
421 {{ if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
422 {{ include "common.certManager.volumesReadOnly" . | nindent 6 }}
426 - name: policy-shared
429 {{- include "common.dmaap.provisioning._volumes" . | nindent 6 -}}
430 {{- include "dcaegen2-services-common._externalVolumes" . | nindent 6 }}
432 - name: "{{ include "common.namespace" . }}-docker-registry-key"
438 Template to attach CertPostProcessor which merges CMPv2 truststore with AAF truststore
439 and swaps keystore files.
441 {{- define "dcaegen2-services-common._certPostProcessor" -}}
442 {{- $certDir := default "" .Values.certDirectory . -}}
443 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
444 {{- $cmpv2Certificate := (index .Values.certificates 0) -}}
445 {{- $cmpv2CertificateDir := $cmpv2Certificate.mountPath -}}
446 {{- $certType := "pem" -}}
447 {{- if $cmpv2Certificate.keystore -}}
448 {{- $certType = (index $cmpv2Certificate.keystore.outputType 0) -}}
450 {{- $truststoresPaths := printf "%s/%s:%s/%s" $certDir "cacert.pem" $cmpv2CertificateDir "cacert.pem" -}}
451 {{- $truststoresPasswordPaths := ":" -}}
452 {{- $keystoreSourcePaths := printf "%s/%s:%s/%s" $cmpv2CertificateDir "cert.pem" $cmpv2CertificateDir "key.pem" -}}
453 {{- $keystoreDestinationPaths := printf "%s/%s:%s/%s" $certDir "cert.pem" $certDir "key.pem" -}}
454 {{- if not (eq $certType "pem") -}}
455 {{- $truststoresPaths = printf "%s/%s:%s/%s.%s" $certDir "trust.jks" $cmpv2CertificateDir "truststore" $certType -}}
456 {{- $truststoresPasswordPaths = printf "%s/%s:%s/%s" $certDir "trust.pass" $cmpv2CertificateDir "truststore.pass" -}}
457 {{- $keystoreSourcePaths = printf "%s/%s.%s:%s/%s" $cmpv2CertificateDir "keystore" $certType $cmpv2CertificateDir "keystore.pass" -}}
458 {{- $keystoreDestinationPaths = printf "%s/%s.%s:%s/%s.pass" $certDir "cert" $certType $certDir $certType -}}
460 - name: cert-post-processor
461 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.certPostProcessorImage }}
462 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
464 {{- include "common.resources" . | nindent 4 }}
466 - mountPath: {{ $certDir }}
468 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 4 }}
470 - name: TRUSTSTORES_PATHS
471 value: {{ $truststoresPaths | quote}}
472 - name: TRUSTSTORES_PASSWORDS_PATHS
473 value: {{ $truststoresPasswordPaths | quote }}
474 - name: KEYSTORE_SOURCE_PATHS
475 value: {{ $keystoreSourcePaths | quote }}
476 - name: KEYSTORE_DESTINATION_PATHS
477 value: {{ $keystoreDestinationPaths | quote }}
482 Template returns string "true" if CMPv2 certificates should be used and nothing (so it can be used in with statements)
483 when they shouldn't. Example use:
484 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
487 {{- define "dcaegen2-services-common.shouldUseCmpv2Certificates" -}}
488 {{- $certDir := default "" .Values.certDirectory . -}}
489 {{- if (and $certDir .Values.certificates .Values.global.cmpv2Enabled .Values.useCmpv2Certificates) -}}