_redis.tpl 3.3 KB

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