Update git submodules
[oom.git] / kubernetes / common / common / templates / _storage.tpl
1 {{/*
2 # Copyright © 2019 Amdocs, Bell Canada, Orange
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   Expand the name of the storage class.
19   The value "common.fullname"-data is used by default,
20   unless either override mechanism is used.
21
22   - .Values.global.persistence.storageClass  : override default storageClass for all charts
23   - .Values.persistence.storageClassOverride : override global and default storage class on a per chart basis
24   - .Values.persistence.storageClass         : override default storage class on a per chart basis
25 */}}
26 {{- define "common.storageClass" -}}
27   {{- if .Values.persistence.storageClassOverride -}}
28     {{- if ne "-" .Values.persistence.storageClassOverride -}}
29       {{- printf "%s" .Values.persistence.storageClassOverride -}}
30     {{- else -}}
31       {{- $storage_class := "" -}}
32       {{- printf "%q" $storage_class -}}
33     {{- end -}}
34   {{- else -}}
35     {{- if or .Values.persistence.storageClass .Values.global.persistence.storageClass }}
36       {{- if ne "-" (default .Values.persistence.storageClass .Values.global.persistence.storageClass) -}}
37         {{- printf "%s" (default .Values.persistence.storageClass .Values.global.persistence.storageClass) -}}
38       {{- else -}}
39         {{- $storage_class := "" -}}
40         {{- printf "%q" $storage_class -}}
41       {{- end -}}
42     {{- else -}}
43       {{- printf "%s-data" (include "common.fullname" .) -}}
44     {{- end -}}
45   {{- end -}}
46 {{- end -}}
47
48 {{/*
49   Calculate if we need a PV. If a storageClass is provided, then we don't need.
50 */}}
51 {{- define "common.needPV" -}}
52 {{- if not (or (or .Values.persistence.storageClassOverride .Values.persistence.storageClass) .Values.global.persistence.storageClass) -}}
53   True
54 {{- end -}}
55 {{- end -}}
56
57 {{/*
58   Generate N PV for a statefulset
59 */}}
60 {{- define "common.replicaPV" -}}
61 {{- $global := . }}
62 {{- if and $global.Values.persistence.enabled (not $global.Values.persistence.existingClaim) }}
63 {{- if (include "common.needPV" .) -}}
64 {{- range $i := until (int $global.Values.replicaCount)}}
65 ---
66 kind: PersistentVolume
67 apiVersion: v1
68 metadata:
69   name: {{ include "common.fullname" $global }}-data-{{$i}}
70   namespace: {{ include "common.namespace" $global }}
71   labels: {{- include "common.labels" $global | nindent 4 }}
72 spec:
73   capacity:
74     storage: {{ $global.Values.persistence.size}}
75   accessModes:
76     - {{ $global.Values.persistence.accessMode }}
77   persistentVolumeReclaimPolicy: {{ $global.Values.persistence.volumeReclaimPolicy }}
78   storageClassName: "{{ include "common.fullname" $global }}-data"
79   hostPath:
80     path: {{ $global.Values.global.persistence.mountPath | default $global.Values.persistence.mountPath }}/{{ include "common.release" $global }}/{{ $global.Values.persistence.mountSubPath }}-{{$i}}
81 {{- end -}}
82 {{- end -}}
83 {{- end -}}
84 {{- end -}}