blob: 1312d98009b23c3e1baa810d164fabb3743c5ad5 [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 }}
rope252f2db5c12022-01-10 14:15:16 +000050 securityContext:
51 runAsUser: 0
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020052 volumeMounts:
53 - mountPath: {{ $initRoot.mountPath }}
54 name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +020055 - mountPath: /opt/app/aaf_config/cert/truststoreONAPall.jks.b64
56 name: aaf-agent-certs
57 subPath: truststoreONAPall.jks.b64
58 - mountPath: /opt/app/aaf_config/cert/truststoreONAP.p12.b64
59 name: aaf-agent-certs
60 subPath: truststoreONAP.p12.b64
Sylvain Desbureauxb8341592021-02-23 15:54:00 +010061 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
62 mountPath: /opt/app/aaf_config/bin/retrieval_check.sh
63 subPath: retrieval_check.sh
Sylvain Desbureauxda711dd2021-04-07 17:22:42 +020064{{- if hasKey $initRoot "ingressTlsSecret" }}
65 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
66 mountPath: /opt/app/aaf_config/bin/tls_certs_configure.sh
67 subPath: tls_certs_configure.sh
68{{- end }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020069{{- if $initRoot.aaf_add_config }}
70 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
71 mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh
72 subPath: aaf-add-config.sh
73{{- end }}
74 command:
75 - sh
76 - -c
77 - |
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020078 /opt/app/aaf_config/bin/agent.sh
Guillaume Lambert2b6f82c2021-03-02 21:45:00 +010079 . /opt/app/aaf_config/bin/retrieval_check.sh
Sylvain Desbureauxda711dd2021-04-07 17:22:42 +020080{{- if hasKey $initRoot "ingressTlsSecret" }}
81 /opt/app/aaf_config/bin/tls_certs_configure.sh
82{{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020083{{- if $initRoot.aaf_add_config }}
84 /opt/app/aaf_config/bin/aaf-add-config.sh
85{{- end }}
86 env:
87 - name: APP_FQI
88 value: "{{ $initRoot.fqi }}"
xuegao8055f5a2021-12-08 09:26:42 +010089 {{- if $initRoot.aaf_namespace }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020090 - name: aaf_locate_url
xuegao8055f5a2021-12-08 09:26:42 +010091 value: "https://aaf-locate.{{ $initRoot.aaf_namespace }}:8095"
92 - name: aaf_locator_container_ns
93 value: "{{ $initRoot.aaf_namespace }}"
94 {{- else }}
95 - name: aaf_locate_url
96 value: "https://aaf-locate.{{ $dot.Release.Namespace }}:8095"
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +020097 - name: aaf_locator_container_ns
98 value: "{{ $dot.Release.Namespace }}"
xuegao8055f5a2021-12-08 09:26:42 +010099 {{- end }}
100 - name: aaf_locator_container
101 value: "oom"
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200102 - name: aaf_locator_fqdn
103 value: "{{ $initRoot.fqdn }}"
104 - name: aaf_locator_app_ns
105 value: "{{ $initRoot.app_ns }}"
106 - name: DEPLOY_FQI
107 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "login") | indent 6 }}
108 - name: DEPLOY_PASSWORD
109 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "password") | indent 6 }}
110 #Note: want to put this on Nodes, eventually
111 - name: cadi_longitude
112 value: "{{ default "52.3" $initRoot.cadi_longitude }}"
113 - name: cadi_latitude
114 value: "{{ default "13.2" $initRoot.cadi_latitude }}"
115 #Hello specific. Clients don't don't need this, unless Registering with AAF Locator
116 - name: aaf_locator_public_fqdn
117 value: "{{ $initRoot.public_fqdn | default "" }}"
118{{- end -}}
119
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400120{{/*
121 This init container will import custom .pem certificates to truststoreONAPall.jks
122 Custom certificates must be placed in common/certInitializer/resources directory.
123
124 The feature is enabled by setting Values.global.importCustomCertsEnabled = true
125 It can be used independently of aafEnabled, however it requires the same includes
126 as describe above for _initContainer.
127
128 When AAF is enabled the truststoreONAPAll.jks (which contains AAF CA) will be used
129 to import custom certificates, otherwise the default java keystore will be used.
130
131 The updated truststore file will be placed in /updatedTruststore and can be mounted per component
132 to a specific path by defining Values.certInitializer.truststoreMountpath (see _trustStoreVolumeMount)
133 The truststore file will be available to mount even if no custom certificates were imported.
134*/}}
135{{- define "common.certInitializer._initImportCustomCertsContainer" -}}
136{{- $dot := default . .dot -}}
137{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
138{{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
139- name: {{ include "common.name" $dot }}-import-custom-certs
Sylvain Desbureaux145140b2020-11-19 16:48:39 +0100140 image: {{ include "repositoryGenerator.image.jre" $subchartDot }}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400141 imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
142 securityContext:
143 runAsUser: 0
144 command:
Sylvain Desbureaux36389672021-01-19 14:51:24 +0100145 - /bin/sh
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400146 - -c
147 - /root/import-custom-certs.sh
148 env:
149 - name: AAF_ENABLED
150 value: "{{ $subchartDot.Values.global.aafEnabled }}"
151 - name: TRUSTSTORE_OUTPUT_FILENAME
152 value: "{{ $initRoot.truststoreOutputFileName }}"
153 - name: TRUSTSTORE_PASSWORD
154 {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "truststore-creds" "key" "password") | indent 6 }}
155 volumeMounts:
156 - mountPath: /certs
157 name: aaf-agent-certs
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +0200158 - mountPath: /more_certs
159 name: provided-custom-certs
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400160 - mountPath: /root/import-custom-certs.sh
161 name: aaf-agent-certs
162 subPath: import-custom-certs.sh
163 - mountPath: /updatedTruststore
164 name: updated-truststore
165{{- end -}}
166
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200167{{- define "common.certInitializer._volumeMount" -}}
168{{- $dot := default . .dot -}}
169{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
krishnaa96edf6f372020-09-09 09:30:58 +0530170- mountPath: {{ $initRoot.appMountPath }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200171 name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
172{{- end -}}
173
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400174{{/*
175 This is used together with _initImportCustomCertsContainer
176 It mounts the updated truststore (with imported custom certificates) to the
177 truststoreMountpath defined in the values file for the component.
178*/}}
179{{- define "common.certInitializer._trustStoreVolumeMount" -}}
180{{- $dot := default . .dot -}}
181{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
182{{- if gt (len $initRoot.truststoreMountpath) 0 }}
183- mountPath: {{ $initRoot.truststoreMountpath }}/{{ $initRoot.truststoreOutputFileName }}
184 name: updated-truststore
185 subPath: {{ $initRoot.truststoreOutputFileName }}
Abdelmuhaimen Seaudi3dc8cc22021-09-05 16:32:22 +0200186- mountPath: /etc/ssl/certs/ca-certificates.crt
187 name: updated-truststore
188 subPath: ca-certificates.crt
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400189{{- end -}}
190{{- end -}}
191
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200192{{- define "common.certInitializer._volumes" -}}
193{{- $dot := default . .dot -}}
194{{- $initRoot := default $dot.Values.certInitializer .initRoot -}}
Krzysztof Opasiakd36040c2021-12-09 21:21:37 +0100195{{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot))}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200196- name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
197 emptyDir:
198 medium: Memory
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +0200199- name: aaf-agent-certs
200 configMap:
Krzysztof Opasiak75f18752020-09-09 20:32:56 +0200201 name: {{ tpl $subchartDot.Values.certsCMName $subchartDot }}
Krzysztof Opasiak95a5f842020-05-06 23:27:18 +0200202 defaultMode: 0700
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +0200203{{- if $dot.Values.global.importCustomCertsEnabled }}
204- name: provided-custom-certs
205{{- if $dot.Values.global.customCertsSecret }}
206 secret:
207 secretName: {{ $dot.Values.global.customCertsSecret }}
208{{- else }}
209{{- if $dot.Values.global.customCertsConfigMap }}
210 configMap:
211 name: {{ $dot.Values.global.customCertsConfigMap }}
212{{- else }}
213 emptyDir:
214 medium: Memory
215{{- end }}
216{{- end }}
217{{- end }}
Krzysztof Opasiak108483c2020-05-14 01:44:30 +0200218- name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
219 configMap:
220 name: {{ include "common.fullname" $subchartDot }}-add-config
221 defaultMode: 0700
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400222{{- if $dot.Values.global.importCustomCertsEnabled }}
223- name: updated-truststore
224 emptyDir: {}
225{{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200226{{- end -}}
227
228{{- define "common.certInitializer.initContainer" -}}
229{{- $dot := default . .dot -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400230 {{- if $dot.Values.global.importCustomCertsEnabled }}
231 {{ include "common.certInitializer._initImportCustomCertsContainer" . }}
232 {{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200233 {{- if $dot.Values.global.aafEnabled }}
234 {{ include "common.certInitializer._initContainer" . }}
235 {{- end -}}
236{{- end -}}
237
238{{- define "common.certInitializer.volumeMount" -}}
239{{- $dot := default . .dot -}}
240 {{- if $dot.Values.global.aafEnabled }}
241 {{- include "common.certInitializer._volumeMount" . }}
242 {{- end -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400243 {{- if $dot.Values.global.importCustomCertsEnabled }}
244 {{- include "common.certInitializer._trustStoreVolumeMount" . }}
245 {{- end -}}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200246{{- end -}}
247
248{{- define "common.certInitializer.volumes" -}}
249{{- $dot := default . .dot -}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -0400250 {{- if or ($dot.Values.global.aafEnabled ) ($dot.Values.global.importCustomCertsEnabled) }}
Krzysztof Opasiak020cdb92020-05-01 01:46:37 +0200251 {{- include "common.certInitializer._volumes" . }}
252 {{- end -}}
253{{- end -}}