blob: 0b076ad08bed7de79c0907c6a2a75194bf5546d9 [file] [log] [blame]
Jack Lucasd41dbdb2021-02-16 11:07:28 -05001{{/*
2#============LICENSE_START========================================================
3# ================================================================================
Jack Lucas1e184212022-03-08 13:35:24 -05004# Copyright (c) 2021-2022 J. F. Lucas. All rights reserved.
vv770de8c5c682021-04-15 12:21:36 -04005# Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
Piotr Marcinkiewicz70625182021-04-29 17:02:37 +02006# Copyright (c) 2021 Nokia. All rights reserved.
ajay_dp001cf5232a2021-04-13 20:48:07 +05307# Copyright (c) 2021 Nordix Foundation.
Jack Lucasd41dbdb2021-02-16 11:07:28 -05008# ================================================================================
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
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
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=========================================================
21*/}}
22{{/*
Jack Lucascbca57d2021-04-05 09:49:46 -040023For internal use only!
24
25dcaegen2-services-common._ms-specific-env-vars:
26This template generates a list of microservice-specific environment variables
27as specified in .Values.applicationEnv. The
28dcaegen2-services-common.microServiceDeployment uses this template
29to add the microservice-specific environment variables to the microservice's container.
30These environment variables are in addition to a standard set of environment variables
31provided to all microservices.
32
33The template expects a single argument, pointing to the caller's global context.
34
35Microservice-specific environment variables can be specified in two ways:
Jack Lucasf86f6292022-06-08 09:12:29 -040036 1. As literal string values. (The values can also be Helm template fragments.)
Jack Lucascbca57d2021-04-05 09:49:46 -040037 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.
39
40The following example shows an example of each type. The example assumes
41that a secret has been created using the OOM common secret mechanism, with
42a secret uid "example-secret" and a key called "password".
43
44applicationEnv:
45 APPLICATION_PASSWORD:
46 secretUid: example-secret
47 key: password
48 APPLICATION_EXAMPLE: "An example value"
49
50The example would set two environment variables on the microservice's container,
51one called "APPLICATION_PASSWORD" with the value set from the "password" key in
52the secret with uid "example-secret", and one called "APPLICATION_EXAMPLE" set to
53the the literal string "An example value".
54*/}}
55{{- define "dcaegen2-services-common._ms-specific-env-vars" -}}
56 {{- $global := . }}
57 {{- if .Values.applicationEnv }}
58 {{- range $envName, $envValue := .Values.applicationEnv }}
59 {{- if kindIs "string" $envValue }}
60- name: {{ $envName }}
efiacor26c1f7a2022-04-25 13:27:18 +010061 value: {{ tpl $envValue $global | quote }}
Jack Lucascbca57d2021-04-05 09:49:46 -040062 {{- else }}
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) }}
65 {{- end }}
66- name: {{ $envName }}
67 {{- include "common.secret.envFromSecretFast" (dict "global" $global "uid" $envValue.secretUid "key" $envValue.key) | indent 2 }}
68 {{- end -}}
69 {{- end }}
70 {{- end }}
71{{- end -}}
72{{/*
Jack Lucase5f71602021-05-10 12:00:02 -040073For internal use only!
74
75dcaegen2-services-common._externalVolumes:
76This template generates a list of volumes associated with the pod,
77based on information provided in .Values.externalVolumes. This
78template works in conjunction with dcaegen2-services-common._externalVolumeMounts
79to give the microservice access to data in volumes created else.
80This initial implementation supports ConfigMaps only, as this is the only
81external volume mounting required by current microservices.
82
Jack Lucasb880f892021-06-07 16:40:31 -040083.Values.externalVolumes is a list of objects. Each object has 3 required fields and 2 optional fields:
Jack Lucase5f71602021-05-10 12:00:02 -040084 - 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
88 deployment time.
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.
94 Defaults to false.
Jack Lucasb880f892021-06-07 16:40:31 -040095 - 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.)
Jack Lucase5f71602021-05-10 12:00:02 -0400100
101Here is an example fragment from a values.yaml file for a microservice:
102
103externalVolumes:
104 - name: my-example-configmap
105 type: configmap
106 mountPath: /opt/app/config
107 - name: '{{ include "common.release" . }}-another-example'
108 type: configmap
109 mountPath: /opt/app/otherconfig
Jack Lucasb880f892021-06-07 16:40:31 -0400110 optional: false
Jack Lucase5f71602021-05-10 12:00:02 -0400111*/}}
112{{- define "dcaegen2-services-common._externalVolumes" -}}
113 {{- $global := . -}}
114 {{- if .Values.externalVolumes }}
115 {{- range $vol := .Values.externalVolumes }}
116 {{- if eq (lower $vol.type) "configmap" }}
Jack Lucasb880f892021-06-07 16:40:31 -0400117 {{- $vname := (tpl $vol.name $global) -}}
118 {{- $opt := hasKey $vol "optional" | ternary $vol.optional true }}
Jack Lucase5f71602021-05-10 12:00:02 -0400119- configMap:
120 defaultMode: 420
121 name: {{ $vname }}
Jack Lucasb880f892021-06-07 16:40:31 -0400122 optional: {{ $opt }}
Jack Lucase5f71602021-05-10 12:00:02 -0400123 name: {{ $vname }}
124 {{- end }}
125 {{- end }}
126 {{- end }}
127{{- end }}
128{{/*
129For internal use only!
130
131dcaegen2-services-common._externalVolumeMounts:
132This template generates a list of volume mounts for the microservice container,
133based on information provided in .Values.externalVolumes. This
134template works in conjunction with dcaegen2-services-common._externalVolumes
135to give the microservice access to data in volumes created else.
136This initial implementation supports ConfigMaps only, as this is the only
137external volume mounting required by current microservices.
138
139See the documentation for dcaegen2-services-common._externalVolumes for
140details on how external volumes are specified in the values.yaml file for
141the microservice.
142*/}}
143{{- define "dcaegen2-services-common._externalVolumeMounts" -}}
144 {{- $global := . -}}
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 }}
151 name: {{ $vname }}
152 readOnly: {{ $readOnly }}
153 {{- end }}
154 {{- end }}
155 {{- end }}
156{{- end }}
157{{/*
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500158dcaegen2-services-common.microserviceDeployment:
159This template produces a Kubernetes Deployment for a DCAE microservice.
160
161All DCAE microservices currently use very similar Deployments. Having a
162common template eliminates a lot of repetition in the individual charts
163for each microservice.
164
165The template expects the full chart context as input. A chart for a
166DCAE microservice references this template using:
167{{ include "dcaegen2-services-common.microserviceDeployment" . }}
168The template directly references data in .Values, and indirectly (through its
169use of templates from the ONAP "common" collection) references data in
170.Release.
171
172The exact content of the Deployment generated from this template
173depends on the content of .Values.
174
175The Deployment always includes a single Pod, with a container that uses
Jack Lucas47c07452022-08-02 09:39:34 -0400176the DCAE microservice image. The image name and tag are specified by
177.Values.image. By default, the image comes from the ONAP repository
178(registry) set up by the common repositoryGenerator template. A different
179repository for the microservice image can be set using
180.Values.imageRepositoryOverride. Note that this repository must not
181require authentication, because there is no way to specify credentials for
182the override repository. imageRepositoryOverride is intended primarily
183for testing purposes.
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500184
185The Deployment Pod may also include a logging sidecar container.
Jack Lucas1e184212022-03-08 13:35:24 -0500186The sidecar is included if .Values.log.path is set. The
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500187logging sidecar and the DCAE microservice container share a
188volume where the microservice logs are written.
189
vv770de8c5c682021-04-15 12:21:36 -0400190Deployed POD may also include a Policy-sync sidecar container.
191The sidecar is included if .Values.policies is set. The
192Policy-sync sidecar polls PolicyEngine (PDP) periodically based
193on .Values.policies.duration and configuration retrieved is shared with
194DCAE Microservice container by common volume. Policy can be retrieved based on
guillaume.lambert30ec3902021-09-14 12:32:24 +0200195list of policyID or filter. An optional policyRelease parameter can be specified
Vijay Venkatesh Kumar6259f502021-07-26 16:53:11 -0400196to override the default policy helm release (used for retreiving the secret containing
197pdp username and password)
198
199Following is example policy config override
200
201dcaePolicySyncImage: onap/org.onap.dcaegen2.deployments.dcae-services-policy-sync:1.0.1
202policies:
203 duration: 300
204 policyRelease: "onap"
205 policyID: |
206 '["onap.vfirewall.tca","onap.vdns.tca"]'
Jack Lucasf86f6292022-06-08 09:12:29 -0400207
208The Deployment includes an initContainer that checks for the
209readiness of other components that the microservice relies on.
210This container is generated by the "common.readinessCheck.waitfor"
211template. See the documentation for this template
212(oom/kubernetes/common/readinessCheck/templates/_readinessCheck.tpl).
213
214If the microservice uses a DMaaP Data Router (DR) feed, the Deployment
215includes an initContainer that makes provisioning requests to the DMaaP
216bus controller (dmaap-bc) to create the feed and to set up a publisher
217and/or subscriber to the feed. The Deployment also includes a second
218initContainer that merges the information returned by the provisioning
219process into the microservice's configuration. See the documentation for
220the common DMaaP provisioning template
221(oom/kubernetes/common/common/templates/_dmaapProvisioning.tpl).
222
223If the microservice acts as a TLS client or server, the Deployment will
224include an initContainer that retrieves certificate information from
225the AAF certificate manager. The information is mounted at the
226mount point specified in .Values.certDirectory. If the microservice is
227a TLS server (indicated by setting .Values.tlsServer to true), the
228certificate information will include a server cert and key, in various
229formats. It will also include the AAF CA cert. If the microservice is
230a TLS client only (indicated by setting .Values.tlsServer to false), the
231certificate information includes only the AAF CA cert.
232
233If the microservice uses certificates from an external CMPv2 provider,
234the Deployment will include an initContainer that performs certificate
235post-processing.
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500236*/}}
237
238{{- define "dcaegen2-services-common.microserviceDeployment" -}}
Jack Lucas1e184212022-03-08 13:35:24 -0500239{{- $log := default dict .Values.log -}}
240{{- $logDir := default "" $log.path -}}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500241{{- $certDir := default "" .Values.certDirectory . -}}
242{{- $tlsServer := default "" .Values.tlsServer -}}
Vijay Venkatesh Kumar6259f502021-07-26 16:53:11 -0400243{{- $commonRelease := print (include "common.release" .) -}}
244{{- $policy := default dict .Values.policies -}}
245{{- $policyRls := default $commonRelease $policy.policyRelease -}}
ajay_dp001cf5232a2021-04-13 20:48:07 +0530246{{- $drFeedConfig := default "" .Values.drFeedConfig -}}
Jack Lucas4b22da92021-12-09 21:54:10 -0500247{{- $dcaeName := print (include "common.fullname" .) }}
248{{- $dcaeLabel := (dict "dcaeMicroserviceName" $dcaeName) -}}
249{{- $dot := . -}}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500250apiVersion: apps/v1
251kind: Deployment
Jack Lucas4b22da92021-12-09 21:54:10 -0500252metadata: {{- include "common.resourceMetadata" (dict "dot" $dot "labels" $dcaeLabel) | nindent 2 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500253spec:
254 replicas: 1
255 selector: {{- include "common.selectors" . | nindent 4 }}
256 template:
257 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
258 spec:
259 initContainers:
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500260 {{ include "common.readinessCheck.waitFor" . | indent 6 | trim }}
ajay_dp001cf5232a2021-04-13 20:48:07 +0530261 {{- include "common.dmaap.provisioning.initContainer" . | nindent 6 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500262 {{- if $certDir }}
263 - name: init-tls
264 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.tlsImage }}
265 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
266 env:
267 - name: TLS_SERVER
268 value: {{ $tlsServer | quote }}
269 - name: POD_IP
270 valueFrom:
271 fieldRef:
272 apiVersion: v1
273 fieldPath: status.podIP
274 resources: {{ include "common.resources" . | nindent 2 }}
275 volumeMounts:
276 - mountPath: /opt/app/osaaf
277 name: tls-info
278 {{- end }}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200279 {{ include "dcaegen2-services-common._certPostProcessor" . | nindent 4 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500280 containers:
Jack Lucas47c07452022-08-02 09:39:34 -0400281 - image: {{ default ( include "repositoryGenerator.repository" . ) .Values.imageRepositoryOverride }}/{{ .Values.image }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500282 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
283 name: {{ include "common.name" . }}
284 env:
Bartosz Gardziejewski041a89a2021-05-19 08:05:00 +0200285 {{- range $cred := .Values.credentials }}
286 - name: {{ $cred.name }}
287 {{- include "common.secret.envFromSecretFast" (dict "global" $ "uid" $cred.uid "key" $cred.key) | indent 10 }}
288 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500289 {{- if $certDir }}
290 - name: DCAE_CA_CERTPATH
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200291 value: {{ $certDir }}/cacert.pem
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500292 {{- end }}
293 - name: CONSUL_HOST
294 value: consul-server.onap
295 - name: CONFIG_BINDING_SERVICE
296 value: config-binding-service
297 - name: CBS_CONFIG_URL
298 value: https://config-binding-service:10443/service_component_all/{{ include "common.name" . }}
299 - name: POD_IP
300 valueFrom:
301 fieldRef:
302 apiVersion: v1
303 fieldPath: status.podIP
Jack Lucascbca57d2021-04-05 09:49:46 -0400304 {{- include "dcaegen2-services-common._ms-specific-env-vars" . | nindent 8 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500305 {{- if .Values.service }}
306 ports: {{ include "common.containerPorts" . | nindent 10 }}
307 {{- end }}
308 {{- if .Values.readiness }}
309 readinessProbe:
310 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 5 }}
311 periodSeconds: {{ .Values.readiness.periodSeconds | default 15 }}
312 timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
313 {{- $probeType := .Values.readiness.type | default "httpGet" -}}
314 {{- if eq $probeType "httpGet" }}
315 httpGet:
316 scheme: {{ .Values.readiness.scheme }}
317 path: {{ .Values.readiness.path }}
318 port: {{ .Values.readiness.port }}
319 {{- end }}
320 {{- if eq $probeType "exec" }}
321 exec:
322 command:
323 {{- range $cmd := .Values.readiness.command }}
324 - {{ $cmd }}
325 {{- end }}
326 {{- end }}
327 {{- end }}
328 resources: {{ include "common.resources" . | nindent 2 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500329 volumeMounts:
Bartosz Gardziejewski4bb3da32021-04-21 12:08:50 +0200330 - mountPath: /app-config
Jack Lucasf86f6292022-06-08 09:12:29 -0400331 name: {{ ternary "app-config-input" "app-config" (not $drFeedConfig) }}
Bartosz Gardziejewski041a89a2021-05-19 08:05:00 +0200332 - mountPath: /app-config-input
333 name: app-config-input
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500334 {{- if $logDir }}
335 - mountPath: {{ $logDir}}
Maciej Wereski7000a7c2021-12-16 12:24:06 +0100336 name: logs
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500337 {{- end }}
338 {{- if $certDir }}
339 - mountPath: {{ $certDir }}
340 name: tls-info
Remigiusz Janeczek7b095032021-05-20 19:39:44 +0200341 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200342 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 8 -}}
343 {{- end -}}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500344 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400345 {{- if $policy }}
346 - name: policy-shared
347 mountPath: /etc/policies
348 {{- end }}
Jack Lucase5f71602021-05-10 12:00:02 -0400349 {{- include "dcaegen2-services-common._externalVolumeMounts" . | nindent 8 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500350 {{- if $logDir }}
Maciej Wereski7000a7c2021-12-16 12:24:06 +0100351 {{ include "common.log.sidecar" . | nindent 6 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500352 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400353 {{- if $policy }}
354 - image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.dcaePolicySyncImage }}
355 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
356 name: policy-sync
357 env:
358 - name: POD_IP
359 valueFrom:
360 fieldRef:
361 apiVersion: v1
362 fieldPath: status.podIP
363 - name: POLICY_SYNC_PDP_USER
364 valueFrom:
365 secretKeyRef:
Prativa Dora54080222022-03-29 09:29:23 +0000366 name: {{ $policyRls }}-policy-xacml-pdp-restserver-creds
vv770de8c5c682021-04-15 12:21:36 -0400367 key: login
368 - name: POLICY_SYNC_PDP_PASS
369 valueFrom:
370 secretKeyRef:
Prativa Dora54080222022-03-29 09:29:23 +0000371 name: {{ $policyRls }}-policy-xacml-pdp-restserver-creds
vv770de8c5c682021-04-15 12:21:36 -0400372 key: password
373 - name: POLICY_SYNC_PDP_URL
Piotr Marcinkiewicz70625182021-04-29 17:02:37 +0200374 value : http{{ if (include "common.needTLS" .) }}s{{ end }}://policy-xacml-pdp:6969
vv770de8c5c682021-04-15 12:21:36 -0400375 - name: POLICY_SYNC_OUTFILE
376 value : "/etc/policies/policies.json"
377 - name: POLICY_SYNC_V1_DECISION_ENDPOINT
378 value : "policy/pdpx/v1/decision"
379 {{- if $policy.filter }}
380 - name: POLICY_SYNC_FILTER
381 value: {{ $policy.filter }}
382 {{- end -}}
383 {{- if $policy.policyID }}
384 - name: POLICY_SYNC_ID
385 value: {{ $policy.policyID }}
386 {{- end -}}
387 {{- if $policy.duration }}
388 - name: POLICY_SYNC_DURATION
Vijay Venkatesh Kumarc269b262021-06-29 13:49:15 -0400389 value: "{{ $policy.duration }}"
vv770de8c5c682021-04-15 12:21:36 -0400390 {{- end }}
391 resources: {{ include "common.resources" . | nindent 2 }}
392 volumeMounts:
393 - mountPath: /etc/policies
394 name: policy-shared
395 {{- if $certDir }}
396 - mountPath: /opt/ca-certificates/
397 name: tls-info
398 {{- end }}
399 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500400 hostname: {{ include "common.name" . }}
farida azmycb03ac72021-09-12 16:14:12 +0200401 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500402 volumes:
403 - configMap:
404 defaultMode: 420
405 name: {{ include "common.fullname" . }}-application-config-configmap
406 name: app-config-input
407 - emptyDir:
408 medium: Memory
409 name: app-config
410 {{- if $logDir }}
411 - emptyDir: {}
Maciej Wereski7000a7c2021-12-16 12:24:06 +0100412 name: logs
413 {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix . )) | nindent 6 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500414 {{- end }}
415 {{- if $certDir }}
416 - emptyDir: {}
417 name: tls-info
Remigiusz Janeczek7b095032021-05-20 19:39:44 +0200418 {{ if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200419 {{ include "common.certManager.volumesReadOnly" . | nindent 6 }}
420 {{- end }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500421 {{- end }}
vv770de8c5c682021-04-15 12:21:36 -0400422 {{- if $policy }}
423 - name: policy-shared
424 emptyDir: {}
425 {{- end }}
ajay_dp001cf5232a2021-04-13 20:48:07 +0530426 {{- include "common.dmaap.provisioning._volumes" . | nindent 6 -}}
Jack Lucase5f71602021-05-10 12:00:02 -0400427 {{- include "dcaegen2-services-common._externalVolumes" . | nindent 6 }}
Jack Lucasd41dbdb2021-02-16 11:07:28 -0500428 imagePullSecrets:
429 - name: "{{ include "common.namespace" . }}-docker-registry-key"
430{{ end -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200431
432{{/*
433 For internal use
434
435 Template to attach CertPostProcessor which merges CMPv2 truststore with AAF truststore
436 and swaps keystore files.
437*/}}
438{{- define "dcaegen2-services-common._certPostProcessor" -}}
439 {{- $certDir := default "" .Values.certDirectory . -}}
Remigiusz Janeczek7b095032021-05-20 19:39:44 +0200440 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200441 {{- $cmpv2Certificate := (index .Values.certificates 0) -}}
442 {{- $cmpv2CertificateDir := $cmpv2Certificate.mountPath -}}
443 {{- $certType := "pem" -}}
444 {{- if $cmpv2Certificate.keystore -}}
445 {{- $certType = (index $cmpv2Certificate.keystore.outputType 0) -}}
446 {{- end -}}
Piotr Marcinkiewicz70625182021-04-29 17:02:37 +0200447 {{- $truststoresPaths := printf "%s/%s:%s/%s" $certDir "cacert.pem" $cmpv2CertificateDir "cacert.pem" -}}
448 {{- $truststoresPasswordPaths := ":" -}}
449 {{- $keystoreSourcePaths := printf "%s/%s:%s/%s" $cmpv2CertificateDir "cert.pem" $cmpv2CertificateDir "key.pem" -}}
Remigiusz Janeczek9b00b562021-04-26 14:37:57 +0200450 {{- $keystoreDestinationPaths := printf "%s/%s:%s/%s" $certDir "cert.pem" $certDir "key.pem" -}}
451 {{- if not (eq $certType "pem") -}}
452 {{- $truststoresPaths = printf "%s/%s:%s/%s.%s" $certDir "trust.jks" $cmpv2CertificateDir "truststore" $certType -}}
453 {{- $truststoresPasswordPaths = printf "%s/%s:%s/%s" $certDir "trust.pass" $cmpv2CertificateDir "truststore.pass" -}}
454 {{- $keystoreSourcePaths = printf "%s/%s.%s:%s/%s" $cmpv2CertificateDir "keystore" $certType $cmpv2CertificateDir "keystore.pass" -}}
455 {{- $keystoreDestinationPaths = printf "%s/%s.%s:%s/%s.pass" $certDir "cert" $certType $certDir $certType -}}
456 {{- end }}
457 - name: cert-post-processor
458 image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.certPostProcessorImage }}
459 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
460 resources:
461 {{- include "common.resources" . | nindent 4 }}
462 volumeMounts:
463 - mountPath: {{ $certDir }}
464 name: tls-info
465 {{- include "common.certManager.volumeMountsReadOnly" . | nindent 4 }}
466 env:
467 - name: TRUSTSTORES_PATHS
468 value: {{ $truststoresPaths | quote}}
469 - name: TRUSTSTORES_PASSWORDS_PATHS
470 value: {{ $truststoresPasswordPaths | quote }}
471 - name: KEYSTORE_SOURCE_PATHS
472 value: {{ $keystoreSourcePaths | quote }}
473 - name: KEYSTORE_DESTINATION_PATHS
474 value: {{ $keystoreDestinationPaths | quote }}
475 {{- end }}
476{{- end -}}
Remigiusz Janeczek7b095032021-05-20 19:39:44 +0200477
478{{/*
479 Template returns string "true" if CMPv2 certificates should be used and nothing (so it can be used in with statements)
480 when they shouldn't. Example use:
481 {{- if (include "dcaegen2-services-common.shouldUseCmpv2Certificates" .) -}}
482
483*/}}
484{{- define "dcaegen2-services-common.shouldUseCmpv2Certificates" -}}
485 {{- $certDir := default "" .Values.certDirectory . -}}
Piotr Marcinkiewicz598f2d82021-06-01 12:36:13 +0200486 {{- if (and $certDir .Values.certificates .Values.global.cmpv2Enabled .Values.useCmpv2Certificates) -}}
Remigiusz Janeczek7b095032021-05-20 19:39:44 +0200487 true
488 {{- end -}}
489{{- end -}}