1 {{/* vim: set filetype=mustache: */}}
3 Expand the name of the chart.
5 {{- define "mongodb.name" -}}
6 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
10 Renders a value that contains template.
12 {{ include "mongodb.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
14 {{- define "mongodb.tplValue" -}}
15 {{- if typeIs "string" .value }}
16 {{- tpl .value .context }}
18 {{- tpl (.value | toYaml) .context }}
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.
27 {{- define "mongodb.fullname" -}}
28 {{- if .Values.fullnameOverride -}}
29 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
31 {{- $name := default .Chart.Name .Values.nameOverride -}}
32 {{- if contains $name .Release.Name -}}
33 {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
35 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
41 Create chart name and version as used by the chart label.
43 {{- define "mongodb.chart" -}}
44 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
48 Create the name for the admin secret.
50 {{- define "mongodb.adminSecret" -}}
51 {{- if .Values.auth.existingAdminSecret -}}
52 {{- .Values.auth.existingAdminSecret -}}
54 {{- template "mongodb.fullname" . -}}-admin
59 Create the name for the key secret.
61 {{- define "mongodb.keySecret" -}}
62 {{- if .Values.auth.existingKeySecret -}}
63 {{- .Values.auth.existingKeySecret -}}
65 {{- template "mongodb.fullname" . -}}-keyfile
70 Return the proper MongoDB image name
72 {{- define "mongodb.image" -}}
73 {{- $registryName := .Values.image.registry -}}
74 {{- $repositoryName := .Values.image.repository -}}
75 {{- $tag := .Values.image.tag | toString -}}
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
81 {{- if .Values.global }}
82 {{- if .Values.global.imageRegistry }}
83 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
85 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
88 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
93 Return the proper image name (for the metrics image)
95 {{- define "mongodb.metrics.image" -}}
96 {{- $registryName := .Values.metrics.image.registry -}}
97 {{- $repositoryName := .Values.metrics.image.repository -}}
98 {{- $tag := .Values.metrics.image.tag | toString -}}
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
104 {{- if .Values.global }}
105 {{- if .Values.global.imageRegistry }}
106 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
108 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
111 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
117 Return the proper Docker Image Registry Secret Names
119 {{- define "mongodb.imagePullSecrets" -}}
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
125 {{- if .Values.global }}
126 {{- if .Values.global.imagePullSecrets }}
128 {{- range .Values.global.imagePullSecrets }}
131 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
133 {{- range .Values.image.pullSecrets }}
136 {{- range .Values.metrics.image.pullSecrets }}
139 {{- range .Values.volumePermissions.image.pullSecrets }}
143 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
145 {{- range .Values.image.pullSecrets }}
148 {{- range .Values.metrics.image.pullSecrets }}
151 {{- range .Values.volumePermissions.image.pullSecrets }}
158 Return the proper image name (for the init container volume-permissions image)
160 {{- define "mongodb.volumePermissions.image" -}}
161 {{- $registryName := .Values.volumePermissions.image.registry -}}
162 {{- $repositoryName := .Values.volumePermissions.image.repository -}}
163 {{- $tag := .Values.volumePermissions.image.tag | toString -}}
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
169 {{- if .Values.global }}
170 {{- if .Values.global.imageRegistry }}
171 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
173 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
176 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
181 Compile all warnings into a single message, and call fail.
183 {{- define "mongodb.validateValues" -}}
184 {{- $messages := list -}}
185 {{- $messages := append $messages (include "mongodb.validateValues.mongodbCustomDatabase" .) -}}
186 {{- $messages := without $messages "" -}}
187 {{- $message := join "\n" $messages -}}
190 {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
195 Validate values of MongoDB - both mongodbUsername and mongodbDatabase are necessary
196 to create a custom user and database during 1st initialization
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")
208 Return the proper Storage Class
210 {{- define "mongodb.storageClass" -}}
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.
215 {{- if .Values.global -}}
216 {{- if .Values.global.storageClass -}}
217 {{- if (eq "-" .Values.global.storageClass) -}}
218 {{- printf "storageClassName: \"\"" -}}
220 {{- printf "storageClassName: %s" .Values.global.storageClass -}}
223 {{- if .Values.persistence.storageClass -}}
224 {{- if (eq "-" .Values.persistence.storageClass) -}}
225 {{- printf "storageClassName: \"\"" -}}
227 {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
232 {{- if .Values.persistence.storageClass -}}
233 {{- if (eq "-" .Values.persistence.storageClass) -}}
234 {{- printf "storageClassName: \"\"" -}}
236 {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
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"
246 {{- define "mongodb.serviceName" -}}
247 {{- if .Values.service.name -}}
248 {{ .Values.service.name }}
250 {{ template "mongodb.fullname" .}}