_validations.tpl 2.5 KB

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