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 # ================================================================================
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 For internal use only!
23 dcaegen2-services-common._ms-specific-env-vars:
24 This template generates a list of microservice-specific environment variables
25 as specified in .Values.applicationEnv. The
26 dcaegen2-services-common.microServiceDeployment uses this template
27 to add the microservice-specific environment variables to the microservice's container.
28 These environment variables are in addition to a standard set of environment variables
29 provided to all microservices.
31 The template expects a single argument, pointing to the caller's global context.
33 Microservice-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.
38 The following example shows an example of each type. The example assumes
39 that a secret has been created using the OOM common secret mechanism, with
40 a secret uid "example-secret" and a key called "password".
44 secretUid: example-secret
46 APPLICATION_EXAMPLE: "An example value"
48 The example would set two environment variables on the microservice's container,
49 one called "APPLICATION_PASSWORD" with the value set from the "password" key in
50 the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
51 the the literal string "An example value".
53 {{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
55 {{- if .Values.applicationEnv }}
56 {{- range $envName, $envValue := .Values.applicationEnv }}
57 {{- if kindIs "string" $envValue }}
58 - name: {{ $envName }}
59 value: {{ $envValue | quote }}
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) }}
64 - name: {{ $envName }}
65 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
71 dcaegen2-services-common.microserviceDeployment:
72 This template produces a Kubernetes Deployment for a DCAE microservice.
74 All DCAE microservices currently use very similar Deployments. Having a
75 common template eliminates a lot of repetition in the individual charts
76 for each microservice.
78 The template expects the full chart context as input. A chart for a
79 DCAE microservice references this template using:
80 {{ include "dcaegen2-services-common.microserviceDeployment" . }}
81 The template directly references data in .Values, and indirectly (through its
82 use of templates from the ONAP "common" collection) references data in
85 The exact content of the Deployment generated from this template
86 depends on the content of .Values.
88 The Deployment always includes a single Pod, with a container that uses
89 the DCAE microservice image.
91 The Deployment Pod may also include a logging sidecar container.
92 The sidecar is included if .Values.logDirectory is set. The
93 logging sidecar and the DCAE microservice container share a
94 volume where the microservice logs are written.
96 The Deployment includes an initContainer that pushes the
97 microservice's initial configuration (from .Values.applicationConfig)
98 into Consul. All DCAE microservices retrieve their initial
99 configurations by making an API call to a DCAE platform component called
100 the config-binding-service. The config-binding-service currently
101 retrieves configuration information from Consul.
103 The Deployment also includes an initContainer that checks for the
104 readiness of other components that the microservice relies on.
105 This container is generated by the "common.readinessCheck.waitfor"
108 If the microservice acts as a TLS client or server, the Deployment will
109 include an initContainer that retrieves certificate information from
110 the AAF certificate manager. The information is mounted at the
111 mount point specified in .Values.certDirectory. If the microservice is
112 a TLS server (indicated by setting .Values.tlsServer to true), the
113 certificate information will include a server cert and key, in various
114 formats. It will also include the AAF CA cert. If the microservice is
115 a TLS client only (indicated by setting .Values.tlsServer to false), the
116 certificate information includes only the AAF CA cert.
118 Deployed POD may also include a Policy-sync sidecar container.
119 The sidecar is included if .Values.policies is set. The
120 Policy-sync sidecar polls PolicyEngine (PDP) periodically based
121 on .Values.policies.duration and configuration retrieved is shared with
122 DCAE Microservice container by common volume. Policy can be retrieved based on
123 list of policyID or filter
126 {{- define "dcaegen2-services-common.microserviceDeployment" -}}
127 {{- $logDir := default "" .Values.logDirectory -}}
128 {{- $certDir := default "" .Values.certDirectory . -}}
129 {{- $tlsServer := default "" .Values.tlsServer -}}
130 {{- $policy := default "" .Values.policies -}}
134 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
137 selector: {{- include "common.selectors" . | nindent 4 }}
139 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
147 {{- range $var := .Values.customEnvVars }}
148 export {{ $var.name }}="{{ $var.value }}";
150 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
152 {{- range $cred := .Values.credentials }}
153 - name: {{ $cred.name }}
154 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
157 - mountPath: /config-input
158 name: app-config-input
161 image: {{ include "repositoryGenerator.image.envsubst" . }}
162 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
163 name: {{ include "common.name" . }}-update-config
165 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
167 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
168 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
171 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
172 resources: {{ include "common.resources" . | nindent 2 }}
174 - mountPath: /app-config
178 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
179 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
182 value: {{ $tlsServer | quote }}
187 fieldPath: status.podIP
188 resources: {{ include "common.resources" . | nindent 2 }}
190 - mountPath: /opt/app/osaaf
193 {{ include "dcaegen2-services-common._certPostProcessor" . | nindent 4 }}
195 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
196 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
197 name: {{ include "common.name" . }}
200 - name: DCAE_CA_CERTPATH
201 value: {{ $certDir }}/cacert.pem
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" . }}
213 fieldPath: status.podIP
214 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
215 {{- if .Values.service }}
216 ports: {{ include "common.containerPorts" . | nindent 10 }}
218 {{- if .Values.readiness }}
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" }}
226 scheme: {{ .Values.readiness.scheme }}
227 path: {{ .Values.readiness.path }}
228 port: {{ .Values.readiness.port }}
230 {{- if eq $probeType "exec" }}
233 {{- range $cmd := .Values.readiness.command }}
238 resources: {{ include "common.resources" . | nindent 2 }}
240 - mountPath: /app-config
243 - mountPath: {{ $logDir}}
247 - mountPath: {{ $certDir }}
249 {{- if and .Values.certificates .Values.global.cmpv2Enabled .Values.global.CMPv2CertManagerIntegration -}}
250 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 8 -}}
254 - name: policy-shared
255 mountPath: /etc/policies
258 - image: {{ include "repositoryGenerator.image.logging" . }}
259 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
266 fieldPath: status.podIP
267 resources: {{ include "common.resources" . | nindent 2 }}
269 - mountPath: /var/log/onap/{{ include "common.name" . }}
271 - mountPath: /usr/share/filebeat/data
273 - mountPath: /usr/share/filebeat/filebeat.yml
275 subPath: filebeat.yml
278 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
279 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
286 fieldPath: status.podIP
287 - name: POLICY_SYNC_PDP_USER
290 name: onap-policy-xacml-pdp-api-creds
292 - name: POLICY_SYNC_PDP_PASS
295 name: onap-policy-xacml-pdp-api-creds
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 }}
307 {{- if $policy.policyID }}
308 - name: POLICY_SYNC_ID
309 value: {{ $policy.policyID }}
311 {{- if $policy.duration }}
312 - name: POLICY_SYNC_DURATION
313 value: {{ $policy.duration }}
315 resources: {{ include "common.resources" . | nindent 2 }}
317 - mountPath: /etc/policies
320 - mountPath: /opt/ca-certificates/
324 hostname: {{ include "common.name" . }}
328 name: {{ include "common.fullname" . }}-application-config-configmap
329 name: app-config-input
340 name: {{ include "common.fullname" . }}-filebeat-configmap
346 {{ if and .Values.certificates .Values.global.cmpv2Enabled .Values.global.CMPv2CertManagerIntegration -}}
347 {{ include "common.certManager.volumesReadOnly" . | nindent 6 }}
351 - name: policy-shared
355 - name: "{{ include "common.namespace" . }}-docker-registry-key"
361 Template to attach CertPostProcessor which merges CMPv2 truststore with AAF truststore
362 and swaps keystore files.
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) -}}
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 -}}
383 - name: cert-post-processor
384 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.certPostProcessorImage }}
385 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
387 {{- include "common.resources" . | nindent 4 }}
389 - mountPath: {{ $certDir }}
391 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 4 }}
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 }}