Tinoj Joseph | dd1fd9d | 2022-08-01 23:59:26 +0530 | [diff] [blame^] | 1 | # Copyright 2022-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | {{/* vim: set filetype=mustache: */}} |
| 16 | {{/* |
| 17 | Expand the name of the chart. |
| 18 | */}} |
| 19 | {{- define "redis.name" -}} |
| 20 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 21 | {{- end -}} |
| 22 | |
| 23 | {{/* |
| 24 | Expand the chart plus release name (used by the chart label) |
| 25 | */}} |
| 26 | {{- define "redis.chart" -}} |
| 27 | {{- printf "%s-%s" .Chart.Name .Chart.Version -}} |
| 28 | {{- end -}} |
| 29 | |
| 30 | {{/* |
| 31 | Create a default fully qualified app name. |
| 32 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 33 | If release name contains chart name it will be used as a full name. |
| 34 | */}} |
| 35 | {{- define "redis.fullname" -}} |
| 36 | {{- if .Values.fullnameOverride -}} |
| 37 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} |
| 38 | {{- else -}} |
| 39 | {{- $name := default .Chart.Name .Values.nameOverride -}} |
| 40 | {{- if contains $name .Release.Name -}} |
| 41 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} |
| 42 | {{- else -}} |
| 43 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} |
| 44 | {{- end -}} |
| 45 | {{- end -}} |
| 46 | {{- end -}} |
| 47 | |
| 48 | {{/* |
| 49 | Return the appropriate apiVersion for networkpolicy. |
| 50 | */}} |
| 51 | {{- define "networkPolicy.apiVersion" -}} |
| 52 | {{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion -}} |
| 53 | {{- print "extensions/v1beta1" -}} |
| 54 | {{- else -}} |
| 55 | {{- print "networking.k8s.io/v1" -}} |
| 56 | {{- end -}} |
| 57 | {{- end -}} |
| 58 | |
| 59 | {{/* |
| 60 | Return the appropriate apiGroup for PodSecurityPolicy. |
| 61 | */}} |
| 62 | {{- define "podSecurityPolicy.apiGroup" -}} |
| 63 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} |
| 64 | {{- print "policy" -}} |
| 65 | {{- else -}} |
| 66 | {{- print "extensions" -}} |
| 67 | {{- end -}} |
| 68 | {{- end -}} |
| 69 | |
| 70 | {{/* |
| 71 | Return the appropriate apiVersion for PodSecurityPolicy. |
| 72 | */}} |
| 73 | {{- define "podSecurityPolicy.apiVersion" -}} |
| 74 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} |
| 75 | {{- print "policy/v1beta1" -}} |
| 76 | {{- else -}} |
| 77 | {{- print "extensions/v1beta1" -}} |
| 78 | {{- end -}} |
| 79 | {{- end -}} |
| 80 | |
| 81 | {{/* |
| 82 | Return the proper Redis(TM) image name |
| 83 | */}} |
| 84 | {{- define "redis.image" -}} |
| 85 | {{- $registryName := .Values.image.registry -}} |
| 86 | {{- $repositoryName := .Values.image.repository -}} |
| 87 | {{- $tag := .Values.image.tag | toString -}} |
| 88 | {{/* |
| 89 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 90 | but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. |
| 91 | Also, we can't use a single if because lazy evaluation is not an option |
| 92 | */}} |
| 93 | {{- if .Values.global }} |
| 94 | {{- if .Values.global.imageRegistry }} |
| 95 | {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} |
| 96 | {{- else -}} |
| 97 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 98 | {{- end -}} |
| 99 | {{- else -}} |
| 100 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 101 | {{- end -}} |
| 102 | {{- end -}} |
| 103 | |
| 104 | {{/* |
| 105 | Return the proper Redis(TM) Sentinel image name |
| 106 | */}} |
| 107 | {{- define "sentinel.image" -}} |
| 108 | {{- $registryName := .Values.sentinel.image.registry -}} |
| 109 | {{- $repositoryName := .Values.sentinel.image.repository -}} |
| 110 | {{- $tag := .Values.sentinel.image.tag | toString -}} |
| 111 | {{/* |
| 112 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 113 | but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. |
| 114 | Also, we can't use a single if because lazy evaluation is not an option |
| 115 | */}} |
| 116 | {{- if .Values.global }} |
| 117 | {{- if .Values.global.imageRegistry }} |
| 118 | {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} |
| 119 | {{- else -}} |
| 120 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 121 | {{- end -}} |
| 122 | {{- else -}} |
| 123 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 124 | {{- end -}} |
| 125 | {{- end -}} |
| 126 | |
| 127 | {{/* |
| 128 | Return the proper image name (for the metrics image) |
| 129 | */}} |
| 130 | {{- define "redis.metrics.image" -}} |
| 131 | {{- $registryName := .Values.metrics.image.registry -}} |
| 132 | {{- $repositoryName := .Values.metrics.image.repository -}} |
| 133 | {{- $tag := .Values.metrics.image.tag | toString -}} |
| 134 | {{/* |
| 135 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 136 | but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. |
| 137 | Also, we can't use a single if because lazy evaluation is not an option |
| 138 | */}} |
| 139 | {{- if .Values.global }} |
| 140 | {{- if .Values.global.imageRegistry }} |
| 141 | {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} |
| 142 | {{- else -}} |
| 143 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 144 | {{- end -}} |
| 145 | {{- else -}} |
| 146 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 147 | {{- end -}} |
| 148 | {{- end -}} |
| 149 | |
| 150 | {{/* |
| 151 | Return the proper image name (for the init container volume-permissions image) |
| 152 | */}} |
| 153 | {{- define "redis.volumePermissions.image" -}} |
| 154 | {{- $registryName := .Values.volumePermissions.image.registry -}} |
| 155 | {{- $repositoryName := .Values.volumePermissions.image.repository -}} |
| 156 | {{- $tag := .Values.volumePermissions.image.tag | toString -}} |
| 157 | {{/* |
| 158 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 159 | but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. |
| 160 | Also, we can't use a single if because lazy evaluation is not an option |
| 161 | */}} |
| 162 | {{- if .Values.global }} |
| 163 | {{- if .Values.global.imageRegistry }} |
| 164 | {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} |
| 165 | {{- else -}} |
| 166 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 167 | {{- end -}} |
| 168 | {{- else -}} |
| 169 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 170 | {{- end -}} |
| 171 | {{- end -}} |
| 172 | |
| 173 | {{/* |
| 174 | Return the path to the cert file. |
| 175 | */}} |
| 176 | {{- define "redis.tlsCert" -}} |
| 177 | {{- required "Certificate filename is required when TLS in enabled" .Values.tls.certFilename | printf "/opt/bitnami/redis/certs/%s" -}} |
| 178 | {{- end -}} |
| 179 | |
| 180 | {{/* |
| 181 | Return the path to the cert key file. |
| 182 | */}} |
| 183 | {{- define "redis.tlsCertKey" -}} |
| 184 | {{- required "Certificate Key filename is required when TLS in enabled" .Values.tls.certKeyFilename | printf "/opt/bitnami/redis/certs/%s" -}} |
| 185 | {{- end -}} |
| 186 | |
| 187 | {{/* |
| 188 | Return the path to the CA cert file. |
| 189 | */}} |
| 190 | {{- define "redis.tlsCACert" -}} |
| 191 | {{- required "Certificate CA filename is required when TLS in enabled" .Values.tls.certCAFilename | printf "/opt/bitnami/redis/certs/%s" -}} |
| 192 | {{- end -}} |
| 193 | |
| 194 | {{/* |
| 195 | Return the path to the DH params file. |
| 196 | */}} |
| 197 | {{- define "redis.tlsDHParams" -}} |
| 198 | {{- if .Values.tls.dhParamsFilename -}} |
| 199 | {{- printf "/opt/bitnami/redis/certs/%s" .Values.tls.dhParamsFilename -}} |
| 200 | {{- end -}} |
| 201 | {{- end -}} |
| 202 | |
| 203 | {{/* |
| 204 | Create the name of the service account to use |
| 205 | */}} |
| 206 | {{- define "redis.serviceAccountName" -}} |
| 207 | {{- if .Values.serviceAccount.create -}} |
| 208 | {{ default (include "redis.fullname" .) .Values.serviceAccount.name }} |
| 209 | {{- else -}} |
| 210 | {{ default "default" .Values.serviceAccount.name }} |
| 211 | {{- end -}} |
| 212 | {{- end -}} |
| 213 | |
| 214 | {{/* |
| 215 | Get the password secret. |
| 216 | */}} |
| 217 | {{- define "redis.secretName" -}} |
| 218 | {{- if .Values.existingSecret -}} |
| 219 | {{- printf "%s" .Values.existingSecret -}} |
| 220 | {{- else -}} |
| 221 | {{- printf "%s" (include "redis.fullname" .) -}} |
| 222 | {{- end -}} |
| 223 | {{- end -}} |
| 224 | |
| 225 | {{/* |
| 226 | Get the password key to be retrieved from Redis(TM) secret. |
| 227 | */}} |
| 228 | {{- define "redis.secretPasswordKey" -}} |
| 229 | {{- if and .Values.existingSecret .Values.existingSecretPasswordKey -}} |
| 230 | {{- printf "%s" .Values.existingSecretPasswordKey -}} |
| 231 | {{- else -}} |
| 232 | {{- printf "redis-password" -}} |
| 233 | {{- end -}} |
| 234 | {{- end -}} |
| 235 | |
| 236 | {{/* |
| 237 | Return Redis(TM) password |
| 238 | */}} |
| 239 | {{- define "redis.password" -}} |
| 240 | {{- if not (empty .Values.global.redis.password) }} |
| 241 | {{- .Values.global.redis.password -}} |
| 242 | {{- else if not (empty .Values.password) -}} |
| 243 | {{- .Values.password -}} |
| 244 | {{- else -}} |
| 245 | {{- randAlphaNum 10 -}} |
| 246 | {{- end -}} |
| 247 | {{- end -}} |
| 248 | |
| 249 | {{/* |
| 250 | Return sysctl image |
| 251 | */}} |
| 252 | {{- define "redis.sysctl.image" -}} |
| 253 | {{- $registryName := default "docker.io" .Values.sysctlImage.registry -}} |
| 254 | {{- $repositoryName := .Values.sysctlImage.repository -}} |
| 255 | {{- $tag := default "buster" .Values.sysctlImage.tag | toString -}} |
| 256 | {{/* |
| 257 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 258 | but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. |
| 259 | Also, we can't use a single if because lazy evaluation is not an option |
| 260 | */}} |
| 261 | {{- if .Values.global }} |
| 262 | {{- if .Values.global.imageRegistry }} |
| 263 | {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} |
| 264 | {{- else -}} |
| 265 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 266 | {{- end -}} |
| 267 | {{- else -}} |
| 268 | {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} |
| 269 | {{- end -}} |
| 270 | {{- end -}} |
| 271 | |
| 272 | {{/* |
| 273 | Return the proper Docker Image Registry Secret Names |
| 274 | */}} |
| 275 | {{- define "redis.imagePullSecrets" -}} |
| 276 | {{/* |
| 277 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 278 | but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic. |
| 279 | Also, we can not use a single if because lazy evaluation is not an option |
| 280 | */}} |
| 281 | {{- if .Values.global }} |
| 282 | {{- if .Values.global.imagePullSecrets }} |
| 283 | imagePullSecrets: |
| 284 | {{- range .Values.global.imagePullSecrets }} |
| 285 | - name: {{ . }} |
| 286 | {{- end }} |
| 287 | {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.sysctlImage.pullSecrets .Values.volumePermissions.image.pullSecrets }} |
| 288 | imagePullSecrets: |
| 289 | {{- range .Values.image.pullSecrets }} |
| 290 | - name: {{ . }} |
| 291 | {{- end }} |
| 292 | {{- range .Values.metrics.image.pullSecrets }} |
| 293 | - name: {{ . }} |
| 294 | {{- end }} |
| 295 | {{- range .Values.sysctlImage.pullSecrets }} |
| 296 | - name: {{ . }} |
| 297 | {{- end }} |
| 298 | {{- range .Values.volumePermissions.image.pullSecrets }} |
| 299 | - name: {{ . }} |
| 300 | {{- end }} |
| 301 | {{- end -}} |
| 302 | {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.sysctlImage.pullSecrets .Values.volumePermissions.image.pullSecrets }} |
| 303 | imagePullSecrets: |
| 304 | {{- range .Values.image.pullSecrets }} |
| 305 | - name: {{ . }} |
| 306 | {{- end }} |
| 307 | {{- range .Values.metrics.image.pullSecrets }} |
| 308 | - name: {{ . }} |
| 309 | {{- end }} |
| 310 | {{- range .Values.sysctlImage.pullSecrets }} |
| 311 | - name: {{ . }} |
| 312 | {{- end }} |
| 313 | {{- range .Values.volumePermissions.image.pullSecrets }} |
| 314 | - name: {{ . }} |
| 315 | {{- end }} |
| 316 | {{- end -}} |
| 317 | {{- end -}} |
| 318 | |
| 319 | {{/* Check if there are rolling tags in the images */}} |
| 320 | {{- define "redis.checkRollingTags" -}} |
| 321 | {{- if and (contains "bitnami/" .Values.image.repository) (not (.Values.image.tag | toString | regexFind "-r\\d+$|sha256:")) }} |
| 322 | WARNING: Rolling tag detected ({{ .Values.image.repository }}:{{ .Values.image.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. |
| 323 | +info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/ |
| 324 | {{- end }} |
| 325 | {{- if and (contains "bitnami/" .Values.sentinel.image.repository) (not (.Values.sentinel.image.tag | toString | regexFind "-r\\d+$|sha256:")) }} |
| 326 | WARNING: Rolling tag detected ({{ .Values.sentinel.image.repository }}:{{ .Values.sentinel.image.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. |
| 327 | +info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/ |
| 328 | {{- end }} |
| 329 | {{- end -}} |
| 330 | |
| 331 | {{/* |
| 332 | Return the proper Storage Class for master |
| 333 | */}} |
| 334 | {{- define "redis.master.storageClass" -}} |
| 335 | {{/* |
| 336 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 337 | but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic. |
| 338 | */}} |
| 339 | {{- if .Values.global -}} |
| 340 | {{- if .Values.global.storageClass -}} |
| 341 | {{- if (eq "-" .Values.global.storageClass) -}} |
| 342 | {{- printf "storageClassName: \"\"" -}} |
| 343 | {{- else }} |
| 344 | {{- printf "storageClassName: %s" .Values.global.storageClass -}} |
| 345 | {{- end -}} |
| 346 | {{- else -}} |
| 347 | {{- if .Values.master.persistence.storageClass -}} |
| 348 | {{- if (eq "-" .Values.master.persistence.storageClass) -}} |
| 349 | {{- printf "storageClassName: \"\"" -}} |
| 350 | {{- else }} |
| 351 | {{- printf "storageClassName: %s" .Values.master.persistence.storageClass -}} |
| 352 | {{- end -}} |
| 353 | {{- end -}} |
| 354 | {{- end -}} |
| 355 | {{- else -}} |
| 356 | {{- if .Values.master.persistence.storageClass -}} |
| 357 | {{- if (eq "-" .Values.master.persistence.storageClass) -}} |
| 358 | {{- printf "storageClassName: \"\"" -}} |
| 359 | {{- else }} |
| 360 | {{- printf "storageClassName: %s" .Values.master.persistence.storageClass -}} |
| 361 | {{- end -}} |
| 362 | {{- end -}} |
| 363 | {{- end -}} |
| 364 | {{- end -}} |
| 365 | |
| 366 | {{/* |
| 367 | Return the proper Storage Class for slave |
| 368 | */}} |
| 369 | {{- define "redis.slave.storageClass" -}} |
| 370 | {{/* |
| 371 | Helm 2.11 supports the assignment of a value to a variable defined in a different scope, |
| 372 | but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic. |
| 373 | */}} |
| 374 | {{- if .Values.global -}} |
| 375 | {{- if .Values.global.storageClass -}} |
| 376 | {{- if (eq "-" .Values.global.storageClass) -}} |
| 377 | {{- printf "storageClassName: \"\"" -}} |
| 378 | {{- else }} |
| 379 | {{- printf "storageClassName: %s" .Values.global.storageClass -}} |
| 380 | {{- end -}} |
| 381 | {{- else -}} |
| 382 | {{- if .Values.slave.persistence.storageClass -}} |
| 383 | {{- if (eq "-" .Values.slave.persistence.storageClass) -}} |
| 384 | {{- printf "storageClassName: \"\"" -}} |
| 385 | {{- else }} |
| 386 | {{- printf "storageClassName: %s" .Values.slave.persistence.storageClass -}} |
| 387 | {{- end -}} |
| 388 | {{- end -}} |
| 389 | {{- end -}} |
| 390 | {{- else -}} |
| 391 | {{- if .Values.slave.persistence.storageClass -}} |
| 392 | {{- if (eq "-" .Values.slave.persistence.storageClass) -}} |
| 393 | {{- printf "storageClassName: \"\"" -}} |
| 394 | {{- else }} |
| 395 | {{- printf "storageClassName: %s" .Values.slave.persistence.storageClass -}} |
| 396 | {{- end -}} |
| 397 | {{- end -}} |
| 398 | {{- end -}} |
| 399 | {{- end -}} |
| 400 | |
| 401 | {{/* |
| 402 | Compile all warnings into a single message, and call fail. |
| 403 | */}} |
| 404 | {{- define "redis.validateValues" -}} |
| 405 | {{- $messages := list -}} |
| 406 | {{- $messages := append $messages (include "redis.validateValues.spreadConstraints" .) -}} |
| 407 | {{- $messages := without $messages "" -}} |
| 408 | {{- $message := join "\n" $messages -}} |
| 409 | |
| 410 | {{- if $message -}} |
| 411 | {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} |
| 412 | {{- end -}} |
| 413 | {{- end -}} |
| 414 | |
| 415 | {{/* Validate values of Redis(TM) - spreadConstrainsts K8s version */}} |
| 416 | {{- define "redis.validateValues.spreadConstraints" -}} |
| 417 | {{- if and (semverCompare "<1.16-0" .Capabilities.KubeVersion.GitVersion) .Values.slave.spreadConstraints -}} |
| 418 | redis: spreadConstraints |
| 419 | Pod Topology Spread Constraints are only available on K8s >= 1.16 |
| 420 | Find more information at https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ |
| 421 | {{- end -}} |
| 422 | {{- end -}} |
| 423 | |
| 424 | {{/* |
| 425 | Renders a value that contains template. |
| 426 | Usage: |
| 427 | {{ include "redis.tplValue" (dict "value" .Values.path.to.the.Value "context" $) }} |
| 428 | */}} |
| 429 | {{- define "redis.tplValue" -}} |
| 430 | {{- if typeIs "string" .value }} |
| 431 | {{- tpl .value .context }} |
| 432 | {{- else }} |
| 433 | {{- tpl (.value | toYaml) .context }} |
| 434 | {{- end }} |
| 435 | {{- end -}} |