Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / validations / _validations.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6 {{/* vim: set filetype=mustache: */}}
7 {{/*
8 Validate values must not be empty.
9
10 Usage:
11 {{- $validateValueConf00 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-00") -}}
12 {{- $validateValueConf01 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-01") -}}
13 {{ include "common.validations.values.empty" (dict "required" (list $validateValueConf00 $validateValueConf01) "context" $) }}
14
15 Validate value params:
16   - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password"
17   - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret"
18   - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password"
19 */}}
20 {{- define "common.validations.values.multiple.empty" -}}
21   {{- range .required -}}
22     {{- include "common.validations.values.single.empty" (dict "valueKey" .valueKey "secret" .secret "field" .field "context" $.context) -}}
23   {{- end -}}
24 {{- end -}}
25
26 {{/*
27 Validate a value must not be empty.
28
29 Usage:
30 {{ include "common.validations.value.empty" (dict "valueKey" "mariadb.password" "secret" "secretName" "field" "my-password" "subchart" "subchart" "context" $) }}
31
32 Validate value params:
33   - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password"
34   - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret"
35   - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password"
36   - subchart - String - Optional - Name of the subchart that the validated password is part of.
37 */}}
38 {{- define "common.validations.values.single.empty" -}}
39   {{- $value := include "common.utils.getValueFromKey" (dict "key" .valueKey "context" .context) }}
40   {{- $subchart := ternary "" (printf "%s." .subchart) (empty .subchart) }}
41
42   {{- if not $value -}}
43     {{- $varname := "my-value" -}}
44     {{- $getCurrentValue := "" -}}
45     {{- if and .secret .field -}}
46       {{- $varname = include "common.utils.fieldToEnvVar" . -}}
47       {{- $getCurrentValue = printf " To get the current value:\n\n        %s\n" (include "common.utils.secret.getvalue" .) -}}
48     {{- end -}}
49     {{- printf "\n    '%s' must not be empty, please add '--set %s%s=$%s' to the command.%s" .valueKey $subchart .valueKey $varname $getCurrentValue -}}
50   {{- end -}}
51 {{- end -}}