2 # Copyright © 2019 Amdocs, Bell Canada, Orange
3 # Modifications Copyright (C) 2022 Bell Canada
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 Give the root folder for ONAP when using host pathes
21 The function takes up to two arguments (inside a dictionary):
22 - .dot : environment (.)
23 - .subPath: the sub path to use, default to
24 ".Values.persistence.mountSubPath"
27 {{ include "common.storageClass" . }}
28 {{ include "common.storageClass" (dict "dot" . "subPath" "my-awesome-subPath") }}
30 {{- define "common.persistencePath" -}}
31 {{- $dot := default . .dot -}}
32 {{- $subPath := default $dot.Values.persistence.mountSubPath .subPath -}}
33 {{ $dot.Values.global.persistence.mountPath | default $dot.Values.persistence.mountPath }}/{{ include "common.release" $dot }}/{{ $subPath }}
37 Expand the name of the storage class.
38 The value "common.fullname"-data is used by default,
39 unless either override mechanism is used.
41 - .Values.global.persistence.storageClass : override default storageClass for
43 - .Values.persistence.storageClassOverride : override global and default
44 storage class on a per chart
46 - .Values.persistence.storageClass : override default storage class on
49 The function takes up to two arguments (inside a dictionary):
50 - .dot : environment (.)
51 - .suffix: suffix to name. if not set, default to "data" when no override
53 - .persistenceInfos: the persitence values to use, default to
54 `.Values.persistence`.
55 Need to be the dict key from `.Values` in string
63 accessMode: ReadWriteOnce
66 then you have to put `.Values.persitence.logs` in
71 {{ include "common.storageClass" . }}
72 {{ include "common.storageClass" (dict "dot" . "suffix" "my-awesome-suffix") }}
73 {{ include "common.storageClass" (dict "dot" . "suffix" "my-awesome-suffix" "persistenceInfos" .Values.persistenceLog) }}
75 {{- define "common.storageClass" -}}
76 {{- $dot := default . .dot -}}
77 {{- $suffix := default "data" .suffix -}}
78 {{- $persistenceInfos := default $dot.Values.persistence .persistenceInfos -}}
79 {{- if $persistenceInfos.storageClassOverride -}}
80 {{- if ne "-" $persistenceInfos.storageClassOverride -}}
81 {{- $persistenceInfos.storageClassOverride -}}
83 {{- $storage_class := "" -}}
84 {{- printf "%q" $storage_class -}}
87 {{- if or $persistenceInfos.storageClass $dot.Values.global.persistence.storageClass }}
88 {{- if ne "-" (default $persistenceInfos.storageClass $dot.Values.global.persistence.storageClass) -}}
89 {{- default $persistenceInfos.storageClass $dot.Values.global.persistence.storageClass -}}
91 {{- $storage_class := "" -}}
92 {{- printf "%q" $storage_class -}}
95 {{- printf "%s-%s" (include "common.fullname" $dot) $suffix -}}
101 Calculate if we need a PV. If a storageClass is provided, then we don't need.
103 {{- define "common.needPV" -}}
104 {{- if not (or (or .Values.persistence.storageClassOverride .Values.persistence.storageClass) .Values.global.persistence.storageClass) -}}
112 The function takes up to three arguments (inside a dictionary):
113 - .dot : environment (.)
114 - .suffix: suffix to name. if not set, default to "data".
115 - .persistenceInfos: the persitence values to use, default to
116 `.Values.persistence`.
117 Need to be the dict key from `.Values` in string
125 accessMode: ReadWriteOnce
128 then you have to put `.Values.persitence.logs` in
132 {{ include "common.PV" . }}
133 {{ include "common.PV" (dict "dot" . "suffix" "my-awesome-suffix" "persistenceInfos".Values.persistenceLog ) }}
134 {{ include "common.PV" (dict "dot" . "subPath" "persistenceInfos" .Values.persistence.log) }}
136 {{- define "common.PV" -}}
137 {{- $dot := default . .dot -}}
138 {{- $suffix := default "data" .suffix -}}
139 {{- $metadata_suffix := ternary "" $suffix (eq $suffix "data") -}}
140 {{- $persistenceInfos := default $dot.Values.persistence .persistenceInfos -}}
141 {{- if and $persistenceInfos.enabled (not $persistenceInfos.existingClaim) -}}
142 {{- if (include "common.needPV" $dot) -}}
143 kind: PersistentVolume
145 metadata: {{- include "common.resourceMetadata" (dict "dot" $dot "suffix" $suffix "labels" $persistenceInfos.labels) | nindent 2 }}
148 storage: {{ $persistenceInfos.size }}
150 - {{ $persistenceInfos.accessMode }}
151 persistentVolumeReclaimPolicy: {{ $persistenceInfos.volumeReclaimPolicy }}
152 storageClassName: "{{ include "common.fullname" $dot }}-{{ $suffix }}"
154 path: {{ include "common.persistencePath" (dict "dot" $dot "subPath" $persistenceInfos.mountSubPath) }}
160 Generate N PV for a statefulset
162 The function takes up to two arguments (inside a dictionary):
163 - .dot : environment (.)
164 - .suffix: suffix to name. if not set, default to "data".
165 - .persistenceInfos: the persitence values to use, default to
166 `.Values.persistence`.
167 Need to be the dict key from `.Values` in string
175 accessMode: ReadWriteOnce
178 then you have to put `.Values.persitence.logs` in
182 {{ include "common.replicaPV" . }}
183 {{ include "common.replicaPV" (dict "dot" . "suffix" "my-awesome-suffix" "persistenceInfos" .Values.persistenceLog) }}
184 {{ include "common.replicaPV" (dict dot" . "subPath" "persistenceInfos" .Values.persistence.log) }}
186 {{- define "common.replicaPV" -}}
187 {{- $dot := default . .dot -}}
188 {{- $suffix := default "data" .suffix -}}
189 {{- $metadata_suffix := ternary "" $suffix (eq $suffix "data") -}}
190 {{- $persistenceInfos := default $dot.Values.persistence .persistenceInfos -}}
191 {{- if and $persistenceInfos.enabled (not $persistenceInfos.existingClaim) -}}
192 {{- if (include "common.needPV" $dot) -}}
193 {{/* TODO: see if we can use "common.PV" after branching F release */}}
194 {{- range $i := until (int $dot.Values.replicaCount) }}
195 {{- $range_suffix := printf "%s-%d" $metadata_suffix $i }}
197 kind: PersistentVolume
199 metadata: {{- include "common.resourceMetadata" (dict "dot" $dot "suffix" $range_suffix "labels" $persistenceInfos.labels) | nindent 2 }}
202 storage: {{ $persistenceInfos.size }}
204 - {{ $persistenceInfos.accessMode }}
205 persistentVolumeReclaimPolicy: {{ $persistenceInfos.volumeReclaimPolicy }}
206 storageClassName: "{{ include "common.fullname" $dot }}-{{ $suffix }}"
208 path: {{ include "common.persistencePath" (dict "dot" $dot "subPath" $persistenceInfos.mountSubPath) }}-{{ $i }}
217 The function takes up to two arguments (inside a dictionary):
218 - .dot : environment (.)
219 - .suffix: suffix to name. if not set, default to "data".
220 - .persistenceInfos: the persitence values to use, default to
221 `.Values.persistence`.
222 Need to be the dict key from `.Values` in string
230 accessMode: ReadWriteOnce
233 then you have to put `.Values.persitence.logs` in
237 {{ include "common.PVC" . }}
238 {{ include "common.PVC" (dict "dot" . "suffix" "my-awesome-suffix" "persistenceInfos" .Values.persistenceLog) }}
239 {{ include "common.PVC" (dict dot" . "subPath" "persistenceInfos" .Values.persistence.log) }}
241 {{- define "common.PVC" -}}
242 {{- $dot := default . .dot -}}
243 {{- $persistenceInfos := default $dot.Values.persistence .persistenceInfos -}}
244 {{- $suffix := default "data" .suffix -}}
245 {{- $metadata_suffix := ternary "" $suffix (eq $suffix "data") -}}
246 {{- if and $persistenceInfos.enabled (not $persistenceInfos.existingClaim) -}}
247 kind: PersistentVolumeClaim
249 {{ include "common.PVCTemplate" (dict "dot" $dot "suffix" $suffix "persistenceInfos" $persistenceInfos) }}
254 Generate a PVC template for a statefulset
256 The function takes up to two arguments (inside a dictionary):
257 - .dot : environment (.)
258 - .suffix: suffix to name. if not set, default to "data".
259 - .persistenceInfos: the persitence values to use, default to
260 `.Values.persistence`.
261 Need to be the dict key from `.Values` in string
269 accessMode: ReadWriteOnce
272 then you have to put `.Values.persitence.logs` in
276 {{ include "common.PVCTemplate" . }}
277 {{ include "common.PVCTemplate" (dict "dot" . "suffix" "my-awesome-suffix" "persistenceInfos" .Values.persistenceLog) }}
278 {{ include "common.PVCTemplate" (dict dot" . "subPath" "persistenceInfos" .Values.persistence.log) }}
280 {{- define "common.PVCTemplate" -}}
281 {{- $dot := default . .dot -}}
282 {{- $persistenceInfos := default $dot.Values.persistence .persistenceInfos -}}
283 {{- $suffix := default "data" .suffix -}}
284 {{- $metadata_suffix := ternary "" $suffix (eq $suffix "data") -}}
285 metadata: {{- include "common.resourceMetadata" (dict "dot" $dot "suffix" $metadata_suffix "annotations" $persistenceInfos.annotations "ignoreHelmChart" .ignoreHelmChart) | nindent 2 }}
288 - {{ $persistenceInfos.accessMode }}
289 storageClassName: {{ include "common.storageClass" (dict "dot" $dot "suffix" $suffix "persistenceInfos" $persistenceInfos ) }}
292 storage: {{ $persistenceInfos.size }}