github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/kafka/charts/common/templates/validations/_validations.tpl (about) 1 {{/* vim: set filetype=mustache: */}} 2 {{/* 3 Validate values must not be empty. 4 5 Usage: 6 {{- $validateValueConf00 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-00") -}} 7 {{- $validateValueConf01 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-01") -}} 8 {{ include "common.validations.values.empty" (dict "required" (list $validateValueConf00 $validateValueConf01) "context" $) }} 9 10 Validate value params: 11 - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password" 12 - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret" 13 - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password" 14 */}} 15 {{- define "common.validations.values.multiple.empty" -}} 16 {{- range .required -}} 17 {{- include "common.validations.values.single.empty" (dict "valueKey" .valueKey "secret" .secret "field" .field "context" $.context) -}} 18 {{- end -}} 19 {{- end -}} 20 21 {{/* 22 Validate a value must not be empty. 23 24 Usage: 25 {{ include "common.validations.value.empty" (dict "valueKey" "mariadb.password" "secret" "secretName" "field" "my-password" "subchart" "subchart" "context" $) }} 26 27 Validate value params: 28 - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password" 29 - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret" 30 - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password" 31 - subchart - String - Optional - Name of the subchart that the validated password is part of. 32 */}} 33 {{- define "common.validations.values.single.empty" -}} 34 {{- $value := include "common.utils.getValueFromKey" (dict "key" .valueKey "context" .context) }} 35 {{- $subchart := ternary "" (printf "%s." .subchart) (empty .subchart) }} 36 37 {{- if not $value -}} 38 {{- $varname := "my-value" -}} 39 {{- $getCurrentValue := "" -}} 40 {{- if and .secret .field -}} 41 {{- $varname = include "common.utils.fieldToEnvVar" . -}} 42 {{- $getCurrentValue = printf " To get the current value:\n\n %s\n" (include "common.utils.secret.getvalue" .) -}} 43 {{- end -}} 44 {{- printf "\n '%s' must not be empty, please add '--set %s%s=$%s' to the command.%s" .valueKey $subchart .valueKey $varname $getCurrentValue -}} 45 {{- end -}} 46 {{- end -}}