Merge "[DOC] Release Notes for Honolulu"
[oom.git] / kubernetes / common / certInitializer / templates / _certInitializer.yaml
1 {{/*
2 # Copyright © 2020 Bell Canada, Samsung Electronics
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16
17
18
19 {{- define "common.certInitializer._aafConfigVolumeName" -}}
20   {{ include "common.fullname" . }}-aaf-config
21 {{- end -}}
22
23 {{- define "common.certInitializer._aafAddConfigVolumeName" -}}
24   {{ print "aaf-add-config" }}
25 {{- end -}}
26
27 {{/*
28   common templates to enable cert initialization for applictaions
29
30   In deployments/jobs/stateful include:
31   initContainers:
32     {{ include "common.certInitializer.initContainer" . | nindent XX }}
33
34   containers:
35     volumeMounts:
36       {{- include "common.certInitializer.volumeMount" . | nindent XX }}
37     volumes:
38       {{- include "common.certInitializer.volume" . | nindent XX}}
39 */}}
40 {{- define "common.certInitializer._initContainer" -}}
41 {{-   $dot := default . .dot -}}
42 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
43 {{-   $initName := default "certInitializer" -}}
44 {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
45 {{ include "common.readinessCheck.waitFor" $subchartDot }}
46 - name: {{ include "common.name" $dot }}-aaf-config
47   image: {{ include "repositoryGenerator.repository" $subchartDot }}/{{ $subchartDot.Values.global.aafAgentImage }}
48   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
49   volumeMounts:
50   - mountPath: {{ $initRoot.mountPath }}
51     name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
52   - mountPath: /opt/app/aaf_config/cert/truststoreONAPall.jks.b64
53     name: aaf-agent-certs
54     subPath: truststoreONAPall.jks.b64
55   - mountPath: /opt/app/aaf_config/cert/truststoreONAP.p12.b64
56     name: aaf-agent-certs
57     subPath: truststoreONAP.p12.b64
58   - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
59     mountPath: /opt/app/aaf_config/bin/retrieval_check.sh
60     subPath: retrieval_check.sh
61 {{-     if $initRoot.aaf_add_config }}
62   - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
63     mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh
64     subPath: aaf-add-config.sh
65 {{-     end }}
66   command:
67     - sh
68     - -c
69     - |
70       /opt/app/aaf_config/bin/agent.sh
71       . /opt/app/aaf_config/bin/retrieval_check.sh
72 {{-     if $initRoot.aaf_add_config }}
73       /opt/app/aaf_config/bin/aaf-add-config.sh
74 {{-     end }}
75   env:
76     - name: APP_FQI
77       value: "{{ $initRoot.fqi }}"
78     - name: aaf_locate_url
79       value: "https://aaf-locate.{{ $dot.Release.Namespace}}:8095"
80     - name: aaf_locator_container
81       value: "oom"
82     - name: aaf_locator_container_ns
83       value: "{{ $dot.Release.Namespace }}"
84     - name: aaf_locator_fqdn
85       value: "{{ $initRoot.fqdn }}"
86     - name: aaf_locator_app_ns
87       value: "{{ $initRoot.app_ns }}"
88     - name: DEPLOY_FQI
89     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "login") | indent 6 }}
90     - name: DEPLOY_PASSWORD
91     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "password") | indent 6 }}
92   #Note: want to put this on Nodes, eventually
93     - name: cadi_longitude
94       value: "{{ default "52.3" $initRoot.cadi_longitude }}"
95     - name: cadi_latitude
96       value: "{{ default "13.2" $initRoot.cadi_latitude }}"
97   #Hello specific.  Clients don't don't need this, unless Registering with AAF Locator
98     - name: aaf_locator_public_fqdn
99       value: "{{ $initRoot.public_fqdn | default "" }}"
100 {{- end -}}
101
102 {{/*
103   This init container will import custom .pem certificates to truststoreONAPall.jks
104   Custom certificates must be placed in common/certInitializer/resources directory.
105
106   The feature is enabled by setting Values.global.importCustomCertsEnabled = true
107   It can be used independently of aafEnabled, however it requires the same includes
108   as describe above for _initContainer.
109
110   When AAF is enabled the truststoreONAPAll.jks (which contains AAF CA) will be used
111   to import custom certificates, otherwise the default java keystore will be used.
112
113   The updated truststore file will be placed in /updatedTruststore and can be mounted per component
114   to a specific path by defining Values.certInitializer.truststoreMountpath (see _trustStoreVolumeMount)
115   The truststore file will be available to mount even if no custom certificates were imported.
116 */}}
117 {{- define "common.certInitializer._initImportCustomCertsContainer" -}}
118 {{-   $dot := default . .dot -}}
119 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
120 {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
121 - name: {{ include "common.name" $dot }}-import-custom-certs
122   image: {{ include "repositoryGenerator.image.jre" $subchartDot }}
123   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
124   securityContext:
125     runAsUser: 0
126   command:
127     - /bin/sh
128     - -c
129     - /root/import-custom-certs.sh
130   env:
131     - name: AAF_ENABLED
132       value: "{{  $subchartDot.Values.global.aafEnabled }}"
133     - name: TRUSTSTORE_OUTPUT_FILENAME
134       value: "{{ $initRoot.truststoreOutputFileName }}"
135     - name: TRUSTSTORE_PASSWORD
136     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "truststore-creds" "key" "password") | indent 6 }}
137   volumeMounts:
138     - mountPath: /certs
139       name: aaf-agent-certs
140     - mountPath: /more_certs
141       name: provided-custom-certs
142     - mountPath: /root/import-custom-certs.sh
143       name: aaf-agent-certs
144       subPath: import-custom-certs.sh
145     - mountPath: /updatedTruststore
146       name: updated-truststore
147 {{- end -}}
148
149 {{- define "common.certInitializer._volumeMount" -}}
150 {{-   $dot := default . .dot -}}
151 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
152 - mountPath: {{ $initRoot.appMountPath }}
153   name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
154 {{- end -}}
155
156 {{/*
157   This is used together with _initImportCustomCertsContainer
158   It mounts the updated truststore (with imported custom certificates) to the
159   truststoreMountpath defined in the values file for the component.
160 */}}
161 {{- define "common.certInitializer._trustStoreVolumeMount" -}}
162 {{-   $dot := default . .dot -}}
163 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
164 {{- if gt (len $initRoot.truststoreMountpath) 0 }}
165 - mountPath: {{ $initRoot.truststoreMountpath }}/{{ $initRoot.truststoreOutputFileName }}
166   name: updated-truststore
167   subPath: {{ $initRoot.truststoreOutputFileName }}
168 {{- end -}}
169 {{- end -}}
170
171 {{- define "common.certInitializer._volumes" -}}
172 {{-   $dot := default . .dot -}}
173 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
174 {{- $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))) }}
175 - name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
176   emptyDir:
177     medium: Memory
178 - name: aaf-agent-certs
179   configMap:
180     name: {{ tpl $subchartDot.Values.certsCMName $subchartDot }}
181     defaultMode: 0700
182 {{- if $dot.Values.global.importCustomCertsEnabled }}
183 - name: provided-custom-certs
184 {{-   if $dot.Values.global.customCertsSecret }}
185   secret:
186     secretName: {{ $dot.Values.global.customCertsSecret }}
187 {{-   else }}
188 {{-     if $dot.Values.global.customCertsConfigMap }}
189   configMap:
190     name: {{ $dot.Values.global.customCertsConfigMap }}
191 {{-     else }}
192   emptyDir:
193     medium: Memory
194 {{-     end }}
195 {{-   end }}
196 {{- end }}
197 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
198   configMap:
199     name: {{ include "common.fullname" $subchartDot }}-add-config
200     defaultMode: 0700
201 {{-     if $dot.Values.global.importCustomCertsEnabled }}
202 - name: updated-truststore
203   emptyDir: {}
204 {{-     end -}}
205 {{- end -}}
206
207 {{- define "common.certInitializer.initContainer" -}}
208 {{-   $dot := default . .dot -}}
209   {{- if $dot.Values.global.importCustomCertsEnabled }}
210     {{ include "common.certInitializer._initImportCustomCertsContainer" . }}
211   {{- end -}}
212   {{- if $dot.Values.global.aafEnabled }}
213     {{ include "common.certInitializer._initContainer" . }}
214   {{- end -}}
215 {{- end -}}
216
217 {{- define "common.certInitializer.volumeMount" -}}
218 {{-   $dot := default . .dot -}}
219   {{- if $dot.Values.global.aafEnabled }}
220     {{- include "common.certInitializer._volumeMount" . }}
221   {{- end -}}
222   {{- if $dot.Values.global.importCustomCertsEnabled }}
223     {{- include "common.certInitializer._trustStoreVolumeMount" . }}
224   {{- end -}}
225 {{- end -}}
226
227 {{- define "common.certInitializer.volumes" -}}
228 {{-   $dot := default . .dot -}}
229   {{- if or ($dot.Values.global.aafEnabled ) ($dot.Values.global.importCustomCertsEnabled) }}
230     {{- include "common.certInitializer._volumes" . }}
231   {{- end -}}
232 {{- end -}}