2 #============LICENSE_START========================================================
3 # ================================================================================
4 # Copyright (c) 2021 J. F. Lucas. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
20 For internal use only!
22 dcaegen2-services-common._ms-specific-env-vars:
23 This template generates a list of microservice-specific environment variables
24 as specified in .Values.applicationEnv. The
25 dcaegen2-services-common.microServiceDeployment uses this template
26 to add the microservice-specific environment variables to the microservice's container.
27 These environment variables are in addition to a standard set of environment variables
28 provided to all microservices.
30 The template expects a single argument, pointing to the caller's global context.
32 Microservice-specific environment variables can be specified in two ways:
33 1. As literal string values.
34 2. As values that are sourced from a secret, identified by the secret's
35 uid and the key within the secret that provides the value.
37 The following example shows an example of each type. The example assumes
38 that a secret has been created using the OOM common secret mechanism, with
39 a secret uid "example-secret" and a key called "password".
43 secretUid: example-secret
45 APPLICATION_EXAMPLE: "An example value"
47 The example would set two environment variables on the microservice's container,
48 one called "APPLICATION_PASSWORD" with the value set from the "password" key in
49 the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
50 the the literal string "An example value".
52 {{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
54 {{- if .Values.applicationEnv }}
55 {{- range $envName, $envValue := .Values.applicationEnv }}
56 {{- if kindIs "string" $envValue }}
57 - name: {{ $envName }}
58 value: {{ $envValue | quote }}
60 {{ if or (not $envValue.secretUid) (not $envValue.key) }}
61 {{ fail (printf "Env %s definition is not a string and does not contain secretUid or key fields" $envName) }}
63 - name: {{ $envName }}
64 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
70 dcaegen2-services-common.microserviceDeployment:
71 This template produces a Kubernetes Deployment for a DCAE microservice.
73 All DCAE microservices currently use very similar Deployments. Having a
74 common template eliminates a lot of repetition in the individual charts
75 for each microservice.
77 The template expects the full chart context as input. A chart for a
78 DCAE microservice references this template using:
79 {{ include "dcaegen2-services-common.microserviceDeployment" . }}
80 The template directly references data in .Values, and indirectly (through its
81 use of templates from the ONAP "common" collection) references data in
84 The exact content of the Deployment generated from this template
85 depends on the content of .Values.
87 The Deployment always includes a single Pod, with a container that uses
88 the DCAE microservice image.
90 The Deployment Pod may also include a logging sidecar container.
91 The sidecar is included if .Values.logDirectory is set. The
92 logging sidecar and the DCAE microservice container share a
93 volume where the microservice logs are written.
95 The Deployment includes an initContainer that pushes the
96 microservice's initial configuration (from .Values.applicationConfig)
97 into Consul. All DCAE microservices retrieve their initial
98 configurations by making an API call to a DCAE platform component called
99 the config-binding-service. The config-binding-service currently
100 retrieves configuration information from Consul.
102 The Deployment also includes an initContainer that checks for the
103 readiness of other components that the microservice relies on.
104 This container is generated by the "common.readinessCheck.waitfor"
107 If the microservice acts as a TLS client or server, the Deployment will
108 include an initContainer that retrieves certificate information from
109 the AAF certificate manager. The information is mounted at the
110 mount point specified in .Values.certDirectory. If the microservice is
111 a TLS server (indicated by setting .Values.tlsServer to true), the
112 certificate information will include a server cert and key, in various
113 formats. It will also include the AAF CA cert. If the microservice is
114 a TLS client only (indicated by setting .Values.tlsServer to false), the
115 certificate information includes only the AAF CA cert.
118 {{- define "dcaegen2-services-common.microserviceDeployment" -}}
119 {{- $logDir := default "" .Values.logDirectory -}}
120 {{- $certDir := default "" .Values.certDirectory . -}}
121 {{- $tlsServer := default "" .Values.tlsServer -}}
124 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
127 selector: {{- include "common.selectors" . | nindent 4 }}
129 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
137 {{- range $var := .Values.customEnvVars }}
138 export {{ $var.name }}="{{ $var.value }}";
140 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
142 {{- range $cred := .Values.credentials }}
143 - name: {{ $cred.name }}
144 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
147 - mountPath: /config-input
148 name: app-config-input
151 image: {{ include "repositoryGenerator.image.envsubst" . }}
152 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
153 name: {{ include "common.name" . }}-update-config
155 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
157 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
158 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
161 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
162 resources: {{ include "common.resources" . | nindent 2 }}
164 - mountPath: /app-config
168 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
169 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
172 value: {{ $tlsServer | quote }}
177 fieldPath: status.podIP
178 resources: {{ include "common.resources" . | nindent 2 }}
180 - mountPath: /opt/app/osaaf
184 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
185 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
186 name: {{ include "common.name" . }}
189 - name: DCAE_CA_CERTPATH
190 value: {{ $certDir}}/cacert.pem
193 value: consul-server.onap
194 - name: CONFIG_BINDING_SERVICE
195 value: config-binding-service
196 - name: CBS_CONFIG_URL
197 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
202 fieldPath: status.podIP
203 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
204 {{- if .Values.service }}
205 ports: {{ include "common.containerPorts" . | nindent 10 }}
207 {{- if .Values.readiness }}
209 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
210 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
211 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
212 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
213 {{- if eq $probeType "httpGet" }}
215 scheme: {{ .Values.readiness.scheme }}
216 path: {{ .Values.readiness.path }}
217 port: {{ .Values.readiness.port }}
219 {{- if eq $probeType "exec" }}
222 {{- range $cmd := .Values.readiness.command }}
227 resources: {{ include "common.resources" . | nindent 2 }}
229 - mountPath: /app-config
232 - mountPath: {{ $logDir}}
236 - mountPath: {{ $certDir }}
240 - image: {{ include "repositoryGenerator.image.logging" . }}
241 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
248 fieldPath: status.podIP
249 resources: {{ include "common.resources" . | nindent 2 }}
251 - mountPath: /var/log/onap/{{ include "common.name" . }}
253 - mountPath: /usr/share/filebeat/data
255 - mountPath: /usr/share/filebeat/filebeat.yml
257 subPath: filebeat.yml
259 hostname: {{ include "common.name" . }}
263 name: {{ include "common.fullname" . }}-application-config-configmap
264 name: app-config-input
275 name: {{ include "common.fullname" . }}-filebeat-configmap
283 - name: "{{ include "common.namespace" . }}-docker-registry-key"