_cassandra.tpl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Validate Cassandra required passwords are not empty.
  4. Usage:
  5. {{ include "common.validations.values.cassandra.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
  6. Params:
  7. - secret - String - Required. Name of the secret where Cassandra values are stored, e.g: "cassandra-passwords-secret"
  8. - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
  9. */}}
  10. {{- define "common.validations.values.cassandra.passwords" -}}
  11. {{- $existingSecret := include "common.cassandra.values.existingSecret" . -}}
  12. {{- $enabled := include "common.cassandra.values.enabled" . -}}
  13. {{- $dbUserPrefix := include "common.cassandra.values.key.dbUser" . -}}
  14. {{- $valueKeyPassword := printf "%s.password" $dbUserPrefix -}}
  15. {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
  16. {{- $requiredPasswords := list -}}
  17. {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "cassandra-password" -}}
  18. {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
  19. {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
  20. {{- end -}}
  21. {{- end -}}
  22. {{/*
  23. Auxiliary function to get the right value for existingSecret.
  24. Usage:
  25. {{ include "common.cassandra.values.existingSecret" (dict "context" $) }}
  26. Params:
  27. - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
  28. */}}
  29. {{- define "common.cassandra.values.existingSecret" -}}
  30. {{- if .subchart -}}
  31. {{- .context.Values.cassandra.dbUser.existingSecret | quote -}}
  32. {{- else -}}
  33. {{- .context.Values.dbUser.existingSecret | quote -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{/*
  37. Auxiliary function to get the right value for enabled cassandra.
  38. Usage:
  39. {{ include "common.cassandra.values.enabled" (dict "context" $) }}
  40. */}}
  41. {{- define "common.cassandra.values.enabled" -}}
  42. {{- if .subchart -}}
  43. {{- printf "%v" .context.Values.cassandra.enabled -}}
  44. {{- else -}}
  45. {{- printf "%v" (not .context.Values.enabled) -}}
  46. {{- end -}}
  47. {{- end -}}
  48. {{/*
  49. Auxiliary function to get the right value for the key dbUser
  50. Usage:
  51. {{ include "common.cassandra.values.key.dbUser" (dict "subchart" "true" "context" $) }}
  52. Params:
  53. - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
  54. */}}
  55. {{- define "common.cassandra.values.key.dbUser" -}}
  56. {{- if .subchart -}}
  57. cassandra.dbUser
  58. {{- else -}}
  59. dbUser
  60. {{- end -}}
  61. {{- end -}}