blob: 32bba457ee1729903a7e9462133526b028880412 [file] [log] [blame]
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +02001{{/*
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04002# Copyright © 2020 Bell Canada, Samsung Electronics
Sylvain Desbureauxda711dd2021-04-07 17:22:42 +02003# Copyright © 2021 Orange
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +02004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16*/}}
17
18
19
20{{- define "common.certInitializer._aafConfigVolumeName" -}}
21 {{ include "common.fullname" . }}-aaf-config
22{{- end -}}
23
24{{- define "common.certInitializer._aafAddConfigVolumeName" -}}
25 {{ print "aaf-add-config" }}
26{{- end -}}
27
28{{/*
29 common templates to enable cert initialization for applictaions
30
31 In deployments/jobs/stateful include:
32 initContainers:
33 {{ include "common.certInitializer.initContainer" . | nindent XX }}
34
35 containers:
36 volumeMounts:
37 {{- include "common.certInitializer.volumeMount" . | nindent XX }}
38 volumes:
39 {{- include "common.certInitializer.volume" . | nindent XX}}
40*/}}
41{{- define "common.certInitializer._initContainer" -}}
42{{- $dot := default . .dot -}}
43{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
44{{- $initName := default "certInitializer" -}}
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020045{{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
Krzysztof Opasiake9754a02020-07-16 21:06:39 +020046{{ include "common.readinessCheck.waitFor" $subchartDot }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020047- name: {{ include "common.name" $dot }}-aaf-config
Sylvain Desbureaux145140b2020-11-19 16:48:39 +010048 image: {{ include "repositoryGenerator.repository" $subchartDot }}/{{ $subchartDot.Values.global.aafAgentImage }}
Krzysztof Opasiak3e5fa9a2020-05-19 00:44:12 +020049 imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020050 volumeMounts:
51 - mountPath: {{ $initRoot.mountPath }}
52 name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +020053 - mountPath: /opt/app/aaf_config/cert/truststoreONAPall.jks.b64
54 name: aaf-agent-certs
55 subPath: truststoreONAPall.jks.b64
56 - mountPath: /opt/app/aaf_config/cert/truststoreONAP.p12.b64
57 name: aaf-agent-certs
58 subPath: truststoreONAP.p12.b64
Sylvain Desbureauxb8341592021-02-23 15:54:00 +010059 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
60 mountPath: /opt/app/aaf_config/bin/retrieval_check.sh
61 subPath: retrieval_check.sh
Sylvain Desbureauxda711dd2021-04-07 17:22:42 +020062{{- if hasKey $initRoot "ingressTlsSecret" }}
63 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
64 mountPath: /opt/app/aaf_config/bin/tls_certs_configure.sh
65 subPath: tls_certs_configure.sh
66{{- end }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020067{{- if $initRoot.aaf_add_config }}
68 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
69 mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh
70 subPath: aaf-add-config.sh
71{{- end }}
72 command:
73 - sh
74 - -c
75 - |
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020076 /opt/app/aaf_config/bin/agent.sh
Guillaume Lambert2b6f82c2021-03-02 21:45:00 +010077 . /opt/app/aaf_config/bin/retrieval_check.sh
Sylvain Desbureauxda711dd2021-04-07 17:22:42 +020078{{- if hasKey $initRoot "ingressTlsSecret" }}
79 /opt/app/aaf_config/bin/tls_certs_configure.sh
80{{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020081{{- if $initRoot.aaf_add_config }}
82 /opt/app/aaf_config/bin/aaf-add-config.sh
83{{- end }}
84 env:
85 - name: APP_FQI
86 value: "{{ $initRoot.fqi }}"
87 - name: aaf_locate_url
88 value: "https://aaf-locate.{{ $dot.Release.Namespace}}:8095"
89 - name: aaf_locator_container
90 value: "oom"
91 - name: aaf_locator_container_ns
92 value: "{{ $dot.Release.Namespace }}"
93 - name: aaf_locator_fqdn
94 value: "{{ $initRoot.fqdn }}"
95 - name: aaf_locator_app_ns
96 value: "{{ $initRoot.app_ns }}"
97 - name: DEPLOY_FQI
98 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "login") | indent 6 }}
99 - name: DEPLOY_PASSWORD
100 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "password") | indent 6 }}
101 #Note: want to put this on Nodes, eventually
102 - name: cadi_longitude
103 value: "{{ default "52.3" $initRoot.cadi_longitude }}"
104 - name: cadi_latitude
105 value: "{{ default "13.2" $initRoot.cadi_latitude }}"
106 #Hello specific. Clients don't don't need this, unless Registering with AAF Locator
107 - name: aaf_locator_public_fqdn
108 value: "{{ $initRoot.public_fqdn | default "" }}"
109{{- end -}}
110
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400111{{/*
112 This init container will import custom .pem certificates to truststoreONAPall.jks
113 Custom certificates must be placed in common/certInitializer/resources directory.
114
115 The feature is enabled by setting Values.global.importCustomCertsEnabled = true
116 It can be used independently of aafEnabled, however it requires the same includes
117 as describe above for _initContainer.
118
119 When AAF is enabled the truststoreONAPAll.jks (which contains AAF CA) will be used
120 to import custom certificates, otherwise the default java keystore will be used.
121
122 The updated truststore file will be placed in /updatedTruststore and can be mounted per component
123 to a specific path by defining Values.certInitializer.truststoreMountpath (see _trustStoreVolumeMount)
124 The truststore file will be available to mount even if no custom certificates were imported.
125*/}}
126{{- define "common.certInitializer._initImportCustomCertsContainer" -}}
127{{- $dot := default . .dot -}}
128{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
129{{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
130- name: {{ include "common.name" $dot }}-import-custom-certs
Sylvain Desbureaux145140b2020-11-19 16:48:39 +0100131 image: {{ include "repositoryGenerator.image.jre" $subchartDot }}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400132 imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
133 securityContext:
134 runAsUser: 0
135 command:
Sylvain Desbureaux36389672021-01-19 14:51:24 +0100136 - /bin/sh
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400137 - -c
138 - /root/import-custom-certs.sh
139 env:
140 - name: AAF_ENABLED
141 value: "{{ $subchartDot.Values.global.aafEnabled }}"
142 - name: TRUSTSTORE_OUTPUT_FILENAME
143 value: "{{ $initRoot.truststoreOutputFileName }}"
144 - name: TRUSTSTORE_PASSWORD
145 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "truststore-creds" "key" "password") | indent 6 }}
146 volumeMounts:
147 - mountPath: /certs
148 name: aaf-agent-certs
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +0200149 - mountPath: /more_certs
150 name: provided-custom-certs
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400151 - mountPath: /root/import-custom-certs.sh
152 name: aaf-agent-certs
153 subPath: import-custom-certs.sh
154 - mountPath: /updatedTruststore
155 name: updated-truststore
156{{- end -}}
157
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200158{{- define "common.certInitializer._volumeMount" -}}
159{{- $dot := default . .dot -}}
160{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
krishnaa96edf6f372020-09-09 09:30:58 +0530161- mountPath: {{ $initRoot.appMountPath }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200162 name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
163{{- end -}}
164
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400165{{/*
166 This is used together with _initImportCustomCertsContainer
167 It mounts the updated truststore (with imported custom certificates) to the
168 truststoreMountpath defined in the values file for the component.
169*/}}
170{{- define "common.certInitializer._trustStoreVolumeMount" -}}
171{{- $dot := default . .dot -}}
172{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
173{{- if gt (len $initRoot.truststoreMountpath) 0 }}
174- mountPath: {{ $initRoot.truststoreMountpath }}/{{ $initRoot.truststoreOutputFileName }}
175 name: updated-truststore
176 subPath: {{ $initRoot.truststoreOutputFileName }}
Abdelmuhaimen Seaudi3dc8cc22021-09-05 16:32:22 +0200177- mountPath: /etc/ssl/certs/ca-certificates.crt
178 name: updated-truststore
179 subPath: ca-certificates.crt
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400180{{- end -}}
181{{- end -}}
182
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200183{{- define "common.certInitializer._volumes" -}}
184{{- $dot := default . .dot -}}
185{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
Krzysztof Opasiak3e5fa9a2020-05-19 00:44:12 +0200186{{- $subchartDot := mergeOverwrite (deepCopy (omit $dot "Values")) (dict "Chart" (set (fromJson (toJson $dot.Chart)) "Name" $initRoot.nameOverride) "Values" (mergeOverwrite (deepCopy $initRoot) (dict "global" $dot.Values.global))) }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200187- name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
188 emptyDir:
189 medium: Memory
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +0200190- name: aaf-agent-certs
191 configMap:
Krzysztof Opasiak75f18752020-09-09 20:32:56 +0200192 name: {{ tpl $subchartDot.Values.certsCMName $subchartDot }}
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +0200193 defaultMode: 0700
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +0200194{{- if $dot.Values.global.importCustomCertsEnabled }}
195- name: provided-custom-certs
196{{- if $dot.Values.global.customCertsSecret }}
197 secret:
198 secretName: {{ $dot.Values.global.customCertsSecret }}
199{{- else }}
200{{- if $dot.Values.global.customCertsConfigMap }}
201 configMap:
202 name: {{ $dot.Values.global.customCertsConfigMap }}
203{{- else }}
204 emptyDir:
205 medium: Memory
206{{- end }}
207{{- end }}
208{{- end }}
Krzysztof Opasiak108483c2020-05-14 01:44:30 +0200209- name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
210 configMap:
211 name: {{ include "common.fullname" $subchartDot }}-add-config
212 defaultMode: 0700
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400213{{- if $dot.Values.global.importCustomCertsEnabled }}
214- name: updated-truststore
215 emptyDir: {}
216{{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200217{{- end -}}
218
219{{- define "common.certInitializer.initContainer" -}}
220{{- $dot := default . .dot -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400221 {{- if $dot.Values.global.importCustomCertsEnabled }}
222 {{ include "common.certInitializer._initImportCustomCertsContainer" . }}
223 {{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200224 {{- if $dot.Values.global.aafEnabled }}
225 {{ include "common.certInitializer._initContainer" . }}
226 {{- end -}}
227{{- end -}}
228
229{{- define "common.certInitializer.volumeMount" -}}
230{{- $dot := default . .dot -}}
231 {{- if $dot.Values.global.aafEnabled }}
232 {{- include "common.certInitializer._volumeMount" . }}
233 {{- end -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400234 {{- if $dot.Values.global.importCustomCertsEnabled }}
235 {{- include "common.certInitializer._trustStoreVolumeMount" . }}
236 {{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200237{{- end -}}
238
239{{- define "common.certInitializer.volumes" -}}
240{{- $dot := default . .dot -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400241 {{- if or ($dot.Values.global.aafEnabled ) ($dot.Values.global.importCustomCertsEnabled) }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200242 {{- include "common.certInitializer._volumes" . }}
243 {{- end -}}
244{{- end -}}