_cassandra.tpl 2.6 KB

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