blob: 80b4cbc77b06dc7cd189be510cd815a8a58ca211 [file] [log] [blame]
Jack Lucasd41dbdb2021-02-16 11:07:28 -05001{{/*
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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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=========================================================
18*/}}
19{{/*
Jack Lucascbca57d2021-04-05 09:49:46 -040020For internal use only!
21
22dcaegen2-services-common._ms-specific-env-vars:
23This template generates a list of microservice-specific environment variables
24as specified in .Values.applicationEnv. The
25dcaegen2-services-common.microServiceDeployment uses this template
26to add the microservice-specific environment variables to the microservice's container.
27These environment variables are in addition to a standard set of environment variables
28provided to all microservices.
29
30The template expects a single argument, pointing to the caller's global context.
31
32Microservice-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.
36
37The following example shows an example of each type. The example assumes
38that a secret has been created using the OOM common secret mechanism, with
39a secret uid "example-secret" and a key called "password".
40
41applicationEnv:
42 APPLICATION_PASSWORD:
43 secretUid: example-secret
44 key: password
45 APPLICATION_EXAMPLE: "An example value"
46
47The example would set two environment variables on the microservice's container,
48one called "APPLICATION_PASSWORD" with the value set from the "password" key in
49the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
50the the literal string "An example value".
51*/}}
52{{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
53 {{- $global := . }}
54 {{- if .Values.applicationEnv }}
55 {{- range $envName, $envValue := .Values.applicationEnv }}
56 {{- if kindIs "string" $envValue }}
57- name: {{ $envName }}
58 value: {{ $envValue | quote }}
59 {{- else }}
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) }}
62 {{- end }}
63- name: {{ $envName }}
64 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
65 {{- end -}}
66 {{- end }}
67 {{- end }}
68{{- end -}}
69{{/*
Jack Lucasd41dbdb2021-02-16 11:07:28 -050070dcaegen2-services-common.microserviceDeployment:
71This template produces a Kubernetes Deployment for a DCAE microservice.
72
73All DCAE microservices currently use very similar Deployments. Having a
74common template eliminates a lot of repetition in the individual charts
75for each microservice.
76
77The template expects the full chart context as input. A chart for a
78DCAE microservice references this template using:
79{{ include "dcaegen2-services-common.microserviceDeployment" . }}
80The template directly references data in .Values, and indirectly (through its
81use of templates from the ONAP "common" collection) references data in
82.Release.
83
84The exact content of the Deployment generated from this template
85depends on the content of .Values.
86
87The Deployment always includes a single Pod, with a container that uses
88the DCAE microservice image.
89
90The Deployment Pod may also include a logging sidecar container.
91The sidecar is included if .Values.logDirectory is set. The
92logging sidecar and the DCAE microservice container share a
93volume where the microservice logs are written.
94
95The Deployment includes an initContainer that pushes the
96microservice's initial configuration (from .Values.applicationConfig)
97into Consul. All DCAE microservices retrieve their initial
98configurations by making an API call to a DCAE platform component called
99the config-binding-service. The config-binding-service currently
100retrieves configuration information from Consul.
101
102The Deployment also includes an initContainer that checks for the
103readiness of other components that the microservice relies on.
104This container is generated by the "common.readinessCheck.waitfor"
105template.
106
107If the microservice acts as a TLS client or server, the Deployment will
108include an initContainer that retrieves certificate information from
109the AAF certificate manager. The information is mounted at the
110mount point specified in .Values.certDirectory. If the microservice is
111a TLS server (indicated by setting .Values.tlsServer to true), the
112certificate information will include a server cert and key, in various
113formats. It will also include the AAF CA cert. If the microservice is
114a TLS client only (indicated by setting .Values.tlsServer to false), the
115certificate information includes only the AAF CA cert.
116*/}}
117
118{{- define "dcaegen2-services-common.microserviceDeployment" -}}
119{{- $logDir := default "" .Values.logDirectory -}}
120{{- $certDir := default "" .Values.certDirectory . -}}
121{{- $tlsServer := default "" .Values.tlsServer -}}
122apiVersion: apps/v1
123kind: Deployment
124metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
125spec:
126 replicas: 1
127 selector: {{- include "common.selectors" . | nindent 4 }}
128 template:
129 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
130 spec:
131 initContainers:
132 - command:
133 - sh
134 args:
135 - -c
136 - |
137 {{- range $var := .Values.customEnvVars }}
138 export {{ $var.name }}="{{ $var.value }}";
139 {{- end }}
140 cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
141 env:
142 {{- range $cred := .Values.credentials }}
143 - name: {{ $cred.name }}
144 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
145 {{- end }}
146 volumeMounts:
147 - mountPath: /config-input
148 name: app-config-input
149 - mountPath: /config
150 name: app-config
151 image: {{ include "repositoryGenerator.image.envsubst" . }}
152 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
153 name: {{ include "common.name" . }}-update-config
154
155 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
156 - name: init-consul
157 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.consulLoaderImage }}
158 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
159 args:
160 - --key-yaml
161 - "{{ include "common.name" . }}|/app-config/application_config.yaml"
162 resources: {{ include "common.resources" . | nindent 2 }}
163 volumeMounts:
164 - mountPath: /app-config
165 name: app-config
166 {{- if $certDir }}
167 - name: init-tls
168 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
169 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
170 env:
171 - name: TLS_SERVER
172 value: {{ $tlsServer | quote }}
173 - name: POD_IP
174 valueFrom:
175 fieldRef:
176 apiVersion: v1
177 fieldPath: status.podIP
178 resources: {{ include "common.resources" . | nindent 2 }}
179 volumeMounts:
180 - mountPath: /opt/app/osaaf
181 name: tls-info
182 {{- end }}
183 containers:
184 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
185 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
186 name: {{ include "common.name" . }}
187 env:
188 {{- if $certDir }}
189 - name: DCAE_CA_CERTPATH
190 value: {{ $certDir}}/cacert.pem
191 {{- end }}
192 - name: CONSUL_HOST
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" . }}
198 - name: POD_IP
199 valueFrom:
200 fieldRef:
201 apiVersion: v1
202 fieldPath: status.podIP
Jack Lucascbca57d2021-04-05 09:49:46 -0400203 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500204 {{- if .Values.service }}
205 ports: {{ include "common.containerPorts" . | nindent 10 }}
206 {{- end }}
207 {{- if .Values.readiness }}
208 readinessProbe:
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" }}
214 httpGet:
215 scheme: {{ .Values.readiness.scheme }}
216 path: {{ .Values.readiness.path }}
217 port: {{ .Values.readiness.port }}
218 {{- end }}
219 {{- if eq $probeType "exec" }}
220 exec:
221 command:
222 {{- range $cmd := .Values.readiness.command }}
223 - {{ $cmd }}
224 {{- end }}
225 {{- end }}
226 {{- end }}
227 resources: {{ include "common.resources" . | nindent 2 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500228 volumeMounts:
Bartosz Gardziejewski4bb3da32021-04-21 12:08:50 +0200229 - mountPath: /app-config
230 name: app-config
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500231 {{- if $logDir }}
232 - mountPath: {{ $logDir}}
233 name: component-log
234 {{- end }}
235 {{- if $certDir }}
236 - mountPath: {{ $certDir }}
237 name: tls-info
238 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500239 {{- if $logDir }}
240 - image: {{ include "repositoryGenerator.image.logging" . }}
241 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
242 name: filebeat
243 env:
244 - name: POD_IP
245 valueFrom:
246 fieldRef:
247 apiVersion: v1
248 fieldPath: status.podIP
249 resources: {{ include "common.resources" . | nindent 2 }}
250 volumeMounts:
251 - mountPath: /var/log/onap/{{ include "common.name" . }}
252 name: component-log
253 - mountPath: /usr/share/filebeat/data
254 name: filebeat-data
255 - mountPath: /usr/share/filebeat/filebeat.yml
256 name: filebeat-conf
257 subPath: filebeat.yml
258 {{- end }}
259 hostname: {{ include "common.name" . }}
260 volumes:
261 - configMap:
262 defaultMode: 420
263 name: {{ include "common.fullname" . }}-application-config-configmap
264 name: app-config-input
265 - emptyDir:
266 medium: Memory
267 name: app-config
268 {{- if $logDir }}
269 - emptyDir: {}
270 name: component-log
271 - emptyDir: {}
272 name: filebeat-data
273 - configMap:
274 defaultMode: 420
275 name: {{ include "common.fullname" . }}-filebeat-configmap
276 name: filebeat-conf
277 {{- end }}
278 {{- if $certDir }}
279 - emptyDir: {}
280 name: tls-info
281 {{- end }}
282 imagePullSecrets:
283 - name: "{{ include "common.namespace" . }}-docker-registry-key"
284{{ end -}}