_mariadb.tpl 4.0 KB

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