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
194 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
195 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
196 name: {{ include "common.name" . }}
199 - name: DCAE_CA_CERTPATH
200 value: {{ $certDir}}/cacert.pem
203 value: consul-server.onap
204 - name: CONFIG_BINDING_SERVICE
205 value: config-binding-service
206 - name: CBS_CONFIG_URL
207 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
212 fieldPath: status.podIP
213 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
214 {{- if .Values.service }}
215 ports: {{ include "common.containerPorts" . | nindent 10 }}
217 {{- if .Values.readiness }}
219 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
220 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
221 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
222 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
223 {{- if eq $probeType "httpGet" }}
225 scheme: {{ .Values.readiness.scheme }}
226 path: {{ .Values.readiness.path }}
227 port: {{ .Values.readiness.port }}
229 {{- if eq $probeType "exec" }}
232 {{- range $cmd := .Values.readiness.command }}
237 resources: {{ include "common.resources" . | nindent 2 }}
239 - mountPath: /app-config
242 - mountPath: {{ $logDir}}
246 - mountPath: {{ $certDir }}
250 - name: policy-shared
251 mountPath: /etc/policies
254 - image: {{ include "repositoryGenerator.image.logging" . }}
255 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
262 fieldPath: status.podIP
263 resources: {{ include "common.resources" . | nindent 2 }}
265 - mountPath: /var/log/onap/{{ include "common.name" . }}
267 - mountPath: /usr/share/filebeat/data
269 - mountPath: /usr/share/filebeat/filebeat.yml
271 subPath: filebeat.yml
274 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
275 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
282 fieldPath: status.podIP
283 - name: POLICY_SYNC_PDP_USER
286 name: onap-policy-xacml-pdp-api-creds
288 - name: POLICY_SYNC_PDP_PASS
291 name: onap-policy-xacml-pdp-api-creds
293 - name: POLICY_SYNC_PDP_URL
294 value : http{{ if (include "common.needTLS" .) }}s{{ end }}://policy-xacml-pdp:6969
295 - name: POLICY_SYNC_OUTFILE
296 value : "/etc/policies/policies.json"
297 - name: POLICY_SYNC_V1_DECISION_ENDPOINT
298 value : "policy/pdpx/v1/decision"
299 {{- if $policy.filter }}
300 - name: POLICY_SYNC_FILTER
301 value: {{ $policy.filter }}
303 {{- if $policy.policyID }}
304 - name: POLICY_SYNC_ID
305 value: {{ $policy.policyID }}
307 {{- if $policy.duration }}
308 - name: POLICY_SYNC_DURATION
309 value: {{ $policy.duration }}
311 resources: {{ include "common.resources" . | nindent 2 }}
313 - mountPath: /etc/policies
316 - mountPath: /opt/ca-certificates/
320 hostname: {{ include "common.name" . }}
324 name: {{ include "common.fullname" . }}-application-config-configmap
325 name: app-config-input
336 name: {{ include "common.fullname" . }}-filebeat-configmap
344 - name: policy-shared
348 - name: "{{ include "common.namespace" . }}-docker-registry-key"