Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / validations / _redis.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6
7 {{/* vim: set filetype=mustache: */}}
8 {{/*
9 Validate Redis® required passwords are not empty.
10
11 Usage:
12 {{ include "common.validations.values.redis.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
13 Params:
14   - secret - String - Required. Name of the secret where redis values are stored, e.g: "redis-passwords-secret"
15   - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
16 */}}
17 {{- define "common.validations.values.redis.passwords" -}}
18   {{- $enabled := include "common.redis.values.enabled" . -}}
19   {{- $valueKeyPrefix := include "common.redis.values.keys.prefix" . -}}
20   {{- $standarizedVersion := include "common.redis.values.standarized.version" . }}
21
22   {{- $existingSecret := ternary (printf "%s%s" $valueKeyPrefix "auth.existingSecret") (printf "%s%s" $valueKeyPrefix "existingSecret") (eq $standarizedVersion "true") }}
23   {{- $existingSecretValue := include "common.utils.getValueFromKey" (dict "key" $existingSecret "context" .context) }}
24
25   {{- $valueKeyRedisPassword := ternary (printf "%s%s" $valueKeyPrefix "auth.password") (printf "%s%s" $valueKeyPrefix "password") (eq $standarizedVersion "true") }}
26   {{- $valueKeyRedisUseAuth := ternary (printf "%s%s" $valueKeyPrefix "auth.enabled") (printf "%s%s" $valueKeyPrefix "usePassword") (eq $standarizedVersion "true") }}
27
28   {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
29     {{- $requiredPasswords := list -}}
30
31     {{- $useAuth := include "common.utils.getValueFromKey" (dict "key" $valueKeyRedisUseAuth "context" .context) -}}
32     {{- if eq $useAuth "true" -}}
33       {{- $requiredRedisPassword := dict "valueKey" $valueKeyRedisPassword "secret" .secret "field" "redis-password" -}}
34       {{- $requiredPasswords = append $requiredPasswords $requiredRedisPassword -}}
35     {{- end -}}
36
37     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
38   {{- end -}}
39 {{- end -}}
40
41 {{/*
42 Auxiliary function to get the right value for enabled redis.
43
44 Usage:
45 {{ include "common.redis.values.enabled" (dict "context" $) }}
46 */}}
47 {{- define "common.redis.values.enabled" -}}
48   {{- if .subchart -}}
49     {{- printf "%v" .context.Values.redis.enabled -}}
50   {{- else -}}
51     {{- printf "%v" (not .context.Values.enabled) -}}
52   {{- end -}}
53 {{- end -}}
54
55 {{/*
56 Auxiliary function to get the right prefix path for the values
57
58 Usage:
59 {{ include "common.redis.values.key.prefix" (dict "subchart" "true" "context" $) }}
60 Params:
61   - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
62 */}}
63 {{- define "common.redis.values.keys.prefix" -}}
64   {{- if .subchart -}}redis.{{- else -}}{{- end -}}
65 {{- end -}}
66
67 {{/*
68 Checks whether the redis chart's includes the standarizations (version >= 14)
69
70 Usage:
71 {{ include "common.redis.values.standarized.version" (dict "context" $) }}
72 */}}
73 {{- define "common.redis.values.standarized.version" -}}
74
75   {{- $standarizedAuth := printf "%s%s" (include "common.redis.values.keys.prefix" .) "auth" -}}
76   {{- $standarizedAuthValues := include "common.utils.getValueFromKey" (dict "key" $standarizedAuth "context" .context) }}
77
78   {{- if $standarizedAuthValues -}}
79     {{- true -}}
80   {{- end -}}
81 {{- end -}}