_mariadb.tpl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Validate MariaDB required passwords are not empty.
  4. Usage:
  5. {{ include "common.validations.values.mariadb.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
  6. Params:
  7. - secret - String - Required. Name of the secret where MariaDB values are stored, e.g: "mysql-passwords-secret"
  8. - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
  9. */}}
  10. {{- define "common.validations.values.mariadb.passwords" -}}
  11. {{- $existingSecret := include "common.mariadb.values.auth.existingSecret" . -}}
  12. {{- $enabled := include "common.mariadb.values.enabled" . -}}
  13. {{- $architecture := include "common.mariadb.values.architecture" . -}}
  14. {{- $authPrefix := include "common.mariadb.values.key.auth" . -}}
  15. {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
  16. {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
  17. {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
  18. {{- $valueKeyReplicationPassword := printf "%s.replicationPassword" $authPrefix -}}
  19. {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
  20. {{- $requiredPasswords := list -}}
  21. {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mariadb-root-password" -}}
  22. {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
  23. {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
  24. {{- if not (empty $valueUsername) -}}
  25. {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mariadb-password" -}}
  26. {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
  27. {{- end -}}
  28. {{- if (eq $architecture "replication") -}}
  29. {{- $requiredReplicationPassword := dict "valueKey" $valueKeyReplicationPassword "secret" .secret "field" "mariadb-replication-password" -}}
  30. {{- $requiredPasswords = append $requiredPasswords $requiredReplicationPassword -}}
  31. {{- end -}}
  32. {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
  33. {{- end -}}
  34. {{- end -}}
  35. {{/*
  36. Auxiliary function to get the right value for existingSecret.
  37. Usage:
  38. {{ include "common.mariadb.values.auth.existingSecret" (dict "context" $) }}
  39. Params:
  40. - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
  41. */}}
  42. {{- define "common.mariadb.values.auth.existingSecret" -}}
  43. {{- if .subchart -}}
  44. {{- .context.Values.mariadb.auth.existingSecret | quote -}}
  45. {{- else -}}
  46. {{- .context.Values.auth.existingSecret | quote -}}
  47. {{- end -}}
  48. {{- end -}}
  49. {{/*
  50. Auxiliary function to get the right value for enabled mariadb.
  51. Usage:
  52. {{ include "common.mariadb.values.enabled" (dict "context" $) }}
  53. */}}
  54. {{- define "common.mariadb.values.enabled" -}}
  55. {{- if .subchart -}}
  56. {{- printf "%v" .context.Values.mariadb.enabled -}}
  57. {{- else -}}
  58. {{- printf "%v" (not .context.Values.enabled) -}}
  59. {{- end -}}
  60. {{- end -}}
  61. {{/*
  62. Auxiliary function to get the right value for architecture
  63. Usage:
  64. {{ include "common.mariadb.values.architecture" (dict "subchart" "true" "context" $) }}
  65. Params:
  66. - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
  67. */}}
  68. {{- define "common.mariadb.values.architecture" -}}
  69. {{- if .subchart -}}
  70. {{- .context.Values.mariadb.architecture -}}
  71. {{- else -}}
  72. {{- .context.Values.architecture -}}
  73. {{- end -}}
  74. {{- end -}}
  75. {{/*
  76. Auxiliary function to get the right value for the key auth
  77. Usage:
  78. {{ include "common.mariadb.values.key.auth" (dict "subchart" "true" "context" $) }}
  79. Params:
  80. - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
  81. */}}
  82. {{- define "common.mariadb.values.key.auth" -}}
  83. {{- if .subchart -}}
  84. mariadb.auth
  85. {{- else -}}
  86. auth
  87. {{- end -}}
  88. {{- end -}}