_redis.tpl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Validate Redis® required passwords are not empty.
  4. Usage:
  5. {{ include "common.validations.values.redis.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
  6. Params:
  7. - secret - String - Required. Name of the secret where redis values are stored, e.g: "redis-passwords-secret"
  8. - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
  9. */}}
  10. {{- define "common.validations.values.redis.passwords" -}}
  11. {{- $enabled := include "common.redis.values.enabled" . -}}
  12. {{- $valueKeyPrefix := include "common.redis.values.keys.prefix" . -}}
  13. {{- $standarizedVersion := include "common.redis.values.standarized.version" . }}
  14. {{- $existingSecret := ternary (printf "%s%s" $valueKeyPrefix "auth.existingSecret") (printf "%s%s" $valueKeyPrefix "existingSecret") (eq $standarizedVersion "true") }}
  15. {{- $existingSecretValue := include "common.utils.getValueFromKey" (dict "key" $existingSecret "context" .context) }}
  16. {{- $valueKeyRedisPassword := ternary (printf "%s%s" $valueKeyPrefix "auth.password") (printf "%s%s" $valueKeyPrefix "password") (eq $standarizedVersion "true") }}
  17. {{- $valueKeyRedisUseAuth := ternary (printf "%s%s" $valueKeyPrefix "auth.enabled") (printf "%s%s" $valueKeyPrefix "usePassword") (eq $standarizedVersion "true") }}
  18. {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
  19. {{- $requiredPasswords := list -}}
  20. {{- $useAuth := include "common.utils.getValueFromKey" (dict "key" $valueKeyRedisUseAuth "context" .context) -}}
  21. {{- if eq $useAuth "true" -}}
  22. {{- $requiredRedisPassword := dict "valueKey" $valueKeyRedisPassword "secret" .secret "field" "redis-password" -}}
  23. {{- $requiredPasswords = append $requiredPasswords $requiredRedisPassword -}}
  24. {{- end -}}
  25. {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
  26. {{- end -}}
  27. {{- end -}}
  28. {{/*
  29. Auxiliary function to get the right value for enabled redis.
  30. Usage:
  31. {{ include "common.redis.values.enabled" (dict "context" $) }}
  32. */}}
  33. {{- define "common.redis.values.enabled" -}}
  34. {{- if .subchart -}}
  35. {{- printf "%v" .context.Values.redis.enabled -}}
  36. {{- else -}}
  37. {{- printf "%v" (not .context.Values.enabled) -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{/*
  41. Auxiliary function to get the right prefix path for the values
  42. Usage:
  43. {{ include "common.redis.values.key.prefix" (dict "subchart" "true" "context" $) }}
  44. Params:
  45. - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
  46. */}}
  47. {{- define "common.redis.values.keys.prefix" -}}
  48. {{- if .subchart -}}redis.{{- else -}}{{- end -}}
  49. {{- end -}}
  50. {{/*
  51. Checks whether the redis chart's includes the standarizations (version >= 14)
  52. Usage:
  53. {{ include "common.redis.values.standarized.version" (dict "context" $) }}
  54. */}}
  55. {{- define "common.redis.values.standarized.version" -}}
  56. {{- $standarizedAuth := printf "%s%s" (include "common.redis.values.keys.prefix" .) "auth" -}}
  57. {{- $standarizedAuthValues := include "common.utils.getValueFromKey" (dict "key" $standarizedAuth "context" .context) }}
  58. {{- if $standarizedAuthValues -}}
  59. {{- true -}}
  60. {{- end -}}
  61. {{- end -}}