updating helm/docker files and database config files
[it/otf.git] / otf-helm / otf / charts / databases / mongodb / templates / _helpers.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 Expand the name of the chart.
4 */}}
5 {{- define "mongodb.name" -}}
6 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7 {{- end -}}
8
9 {{/*
10 Renders a value that contains template.
11 Usage:
12 {{ include "mongodb.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
13 */}}
14 {{- define "mongodb.tplValue" -}}
15     {{- if typeIs "string" .value }}
16         {{- tpl .value .context }}
17     {{- else }}
18         {{- tpl (.value | toYaml) .context }}
19     {{- end }}
20 {{- end -}}
21
22 {{/*
23 Create a default fully qualified app name.
24 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
25 If release name contains chart name it will be used as a full name.
26 */}}
27 {{- define "mongodb.fullname" -}}
28 {{- if .Values.fullnameOverride -}}
29 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
30 {{- else -}}
31 {{- $name := default .Chart.Name .Values.nameOverride -}}
32 {{- if contains $name .Release.Name -}}
33 {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
34 {{- else -}}
35 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
36 {{- end -}}
37 {{- end -}}
38 {{- end -}}
39
40 {{/*
41 Create chart name and version as used by the chart label.
42 */}}
43 {{- define "mongodb.chart" -}}
44 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
45 {{- end -}}
46
47 {{/*
48 Create the name for the admin secret.
49 */}}
50 {{- define "mongodb.adminSecret" -}}
51     {{- if .Values.auth.existingAdminSecret -}}
52         {{- .Values.auth.existingAdminSecret -}}
53     {{- else -}}
54         {{- template "mongodb.fullname" . -}}-admin
55     {{- end -}}
56 {{- end -}}
57
58 {{/*
59 Create the name for the key secret.
60 */}}
61 {{- define "mongodb.keySecret" -}}
62     {{- if .Values.auth.existingKeySecret -}}
63         {{- .Values.auth.existingKeySecret -}}
64     {{- else -}}
65         {{- template "mongodb.fullname" . -}}-keyfile
66     {{- end -}}
67 {{- end -}}
68
69 {{/*
70 Return the proper MongoDB image name
71 */}}
72 {{- define "mongodb.image" -}}
73 {{- $registryName := .Values.image.registry -}}
74 {{- $repositoryName := .Values.image.repository -}}
75 {{- $tag := .Values.image.tag | toString -}}
76 {{/*
77 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
78 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
79 Also, we can't use a single if because lazy evaluation is not an option
80 */}}
81 {{- if .Values.global }}
82     {{- if .Values.global.imageRegistry }}
83         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
84     {{- else -}}
85         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
86     {{- end -}}
87 {{- else -}}
88     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
89 {{- end -}}
90 {{- end -}}
91
92 {{/*
93 Return the proper image name (for the metrics image)
94 */}}
95 {{- define "mongodb.metrics.image" -}}
96 {{- $registryName := .Values.metrics.image.registry -}}
97 {{- $repositoryName := .Values.metrics.image.repository -}}
98 {{- $tag := .Values.metrics.image.tag | toString -}}
99 {{/*
100 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
101 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
102 Also, we can't use a single if because lazy evaluation is not an option
103 */}}
104 {{- if .Values.global }}
105     {{- if .Values.global.imageRegistry }}
106         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
107     {{- else -}}
108         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
109     {{- end -}}
110 {{- else -}}
111     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
112 {{- end -}}
113 {{- end -}}
114
115
116 {{/*
117 Return the proper Docker Image Registry Secret Names
118 */}}
119 {{- define "mongodb.imagePullSecrets" -}}
120 {{/*
121 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
122 but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
123 Also, we can not use a single if because lazy evaluation is not an option
124 */}}
125 {{- if .Values.global }}
126 {{- if .Values.global.imagePullSecrets }}
127 imagePullSecrets:
128 {{- range .Values.global.imagePullSecrets }}
129   - name: {{ . }}
130 {{- end }}
131 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
132 imagePullSecrets:
133 {{- range .Values.image.pullSecrets }}
134   - name: {{ . }}
135 {{- end }}
136 {{- range .Values.metrics.image.pullSecrets }}
137   - name: {{ . }}
138 {{- end }}
139 {{- range .Values.volumePermissions.image.pullSecrets }}
140   - name: {{ . }}
141 {{- end }}
142 {{- end -}}
143 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
144 imagePullSecrets:
145 {{- range .Values.image.pullSecrets }}
146   - name: {{ . }}
147 {{- end }}
148 {{- range .Values.metrics.image.pullSecrets }}
149   - name: {{ . }}
150 {{- end }}
151 {{- range .Values.volumePermissions.image.pullSecrets }}
152   - name: {{ . }}
153 {{- end }}
154 {{- end -}}
155 {{- end -}}
156
157 {{/*
158 Return the proper image name (for the init container volume-permissions image)
159 */}}
160 {{- define "mongodb.volumePermissions.image" -}}
161 {{- $registryName := .Values.volumePermissions.image.registry -}}
162 {{- $repositoryName := .Values.volumePermissions.image.repository -}}
163 {{- $tag := .Values.volumePermissions.image.tag | toString -}}
164 {{/*
165 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
166 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
167 Also, we can't use a single if because lazy evaluation is not an option
168 */}}
169 {{- if .Values.global }}
170     {{- if .Values.global.imageRegistry }}
171         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
172     {{- else -}}
173         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
174     {{- end -}}
175 {{- else -}}
176     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
177 {{- end -}}
178 {{- end -}}
179
180 {{/*
181 Compile all warnings into a single message, and call fail.
182 */}}
183 {{- define "mongodb.validateValues" -}}
184 {{- $messages := list -}}
185 {{- $messages := append $messages (include "mongodb.validateValues.mongodbCustomDatabase" .) -}}
186 {{- $messages := without $messages "" -}}
187 {{- $message := join "\n" $messages -}}
188
189 {{- if $message -}}
190 {{-   printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
191 {{- end -}}
192 {{- end -}}
193
194 {{/*
195 Validate values of MongoDB - both mongodbUsername and mongodbDatabase are necessary
196 to create a custom user and database during 1st initialization
197 */}}
198 {{- define "mongodb.validateValues.mongodbCustomDatabase" -}}
199 {{- if or (and .Values.mongodbUsername (not .Values.mongodbDatabase)) (and (not .Values.mongodbUsername) .Values.mongodbDatabase) }}
200 mongodb: mongodbUsername, mongodbDatabase
201     Both mongodbUsername and mongodbDatabase must be provided to create
202     a custom user and database during 1st initialization.
203     Please set both of them (--set mongodbUsername="xxxx",mongodbDatabase="yyyy")
204 {{- end -}}
205 {{- end -}}
206
207 {{/*
208 Return  the proper Storage Class
209 */}}
210 {{- define "mongodb.storageClass" -}}
211 {{/*
212 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
213 but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
214 */}}
215 {{- if .Values.global -}}
216     {{- if .Values.global.storageClass -}}
217         {{- if (eq "-" .Values.global.storageClass) -}}
218             {{- printf "storageClassName: \"\"" -}}
219         {{- else }}
220             {{- printf "storageClassName: %s" .Values.global.storageClass -}}
221         {{- end -}}
222     {{- else -}}
223         {{- if .Values.persistence.storageClass -}}
224               {{- if (eq "-" .Values.persistence.storageClass) -}}
225                   {{- printf "storageClassName: \"\"" -}}
226               {{- else }}
227                   {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
228               {{- end -}}
229         {{- end -}}
230     {{- end -}}
231 {{- else -}}
232     {{- if .Values.persistence.storageClass -}}
233         {{- if (eq "-" .Values.persistence.storageClass) -}}
234             {{- printf "storageClassName: \"\"" -}}
235         {{- else }}
236             {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
237         {{- end -}}
238     {{- end -}}
239 {{- end -}}
240 {{- end -}}
241
242 {{/*
243 Returns the proper Service name depending if an explicit service name is set
244 in the values file. If the name is not explicitly set it will take the "mongodb.fullname"
245 */}}
246 {{- define "mongodb.serviceName" -}}
247   {{- if .Values.service.name -}}
248     {{ .Values.service.name }}
249   {{- else -}}
250     {{ template "mongodb.fullname" .}}
251   {{- end -}}
252 {{- end -}}