_validations.tpl 2.4 KB

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