_postgresql.tpl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {{/*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Validate PostgreSQL required passwords are not empty.
  8. Usage:
  9. {{ include "common.validations.values.postgresql.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
  10. Params:
  11. - secret - String - Required. Name of the secret where postgresql values are stored, e.g: "postgresql-passwords-secret"
  12. - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
  13. */}}
  14. {{- define "common.validations.values.postgresql.passwords" -}}
  15. {{- $existingSecret := include "common.postgresql.values.existingSecret" . -}}
  16. {{- $enabled := include "common.postgresql.values.enabled" . -}}
  17. {{- $valueKeyPostgresqlPassword := include "common.postgresql.values.key.postgressPassword" . -}}
  18. {{- $valueKeyPostgresqlReplicationEnabled := include "common.postgresql.values.key.replicationPassword" . -}}
  19. {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
  20. {{- $requiredPasswords := list -}}
  21. {{- $requiredPostgresqlPassword := dict "valueKey" $valueKeyPostgresqlPassword "secret" .secret "field" "postgresql-password" -}}
  22. {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlPassword -}}
  23. {{- $enabledReplication := include "common.postgresql.values.enabled.replication" . -}}
  24. {{- if (eq $enabledReplication "true") -}}
  25. {{- $requiredPostgresqlReplicationPassword := dict "valueKey" $valueKeyPostgresqlReplicationEnabled "secret" .secret "field" "postgresql-replication-password" -}}
  26. {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlReplicationPassword -}}
  27. {{- end -}}
  28. {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
  29. {{- end -}}
  30. {{- end -}}
  31. {{/*
  32. Auxiliary function to decide whether evaluate global values.
  33. Usage:
  34. {{ include "common.postgresql.values.use.global" (dict "key" "key-of-global" "context" $) }}
  35. Params:
  36. - key - String - Required. Field to be evaluated within global, e.g: "existingSecret"
  37. */}}
  38. {{- define "common.postgresql.values.use.global" -}}
  39. {{- if .context.Values.global -}}
  40. {{- if .context.Values.global.postgresql -}}
  41. {{- index .context.Values.global.postgresql .key | quote -}}
  42. {{- end -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{/*
  46. Auxiliary function to get the right value for existingSecret.
  47. Usage:
  48. {{ include "common.postgresql.values.existingSecret" (dict "context" $) }}
  49. */}}
  50. {{- define "common.postgresql.values.existingSecret" -}}
  51. {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "existingSecret" "context" .context) -}}
  52. {{- if .subchart -}}
  53. {{- default (.context.Values.postgresql.existingSecret | quote) $globalValue -}}
  54. {{- else -}}
  55. {{- default (.context.Values.existingSecret | quote) $globalValue -}}
  56. {{- end -}}
  57. {{- end -}}
  58. {{/*
  59. Auxiliary function to get the right value for enabled postgresql.
  60. Usage:
  61. {{ include "common.postgresql.values.enabled" (dict "context" $) }}
  62. */}}
  63. {{- define "common.postgresql.values.enabled" -}}
  64. {{- if .subchart -}}
  65. {{- printf "%v" .context.Values.postgresql.enabled -}}
  66. {{- else -}}
  67. {{- printf "%v" (not .context.Values.enabled) -}}
  68. {{- end -}}
  69. {{- end -}}
  70. {{/*
  71. Auxiliary function to get the right value for the key postgressPassword.
  72. Usage:
  73. {{ include "common.postgresql.values.key.postgressPassword" (dict "subchart" "true" "context" $) }}
  74. Params:
  75. - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
  76. */}}
  77. {{- define "common.postgresql.values.key.postgressPassword" -}}
  78. {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "postgresqlUsername" "context" .context) -}}
  79. {{- if not $globalValue -}}
  80. {{- if .subchart -}}
  81. postgresql.postgresqlPassword
  82. {{- else -}}
  83. postgresqlPassword
  84. {{- end -}}
  85. {{- else -}}
  86. global.postgresql.postgresqlPassword
  87. {{- end -}}
  88. {{- end -}}
  89. {{/*
  90. Auxiliary function to get the right value for enabled.replication.
  91. Usage:
  92. {{ include "common.postgresql.values.enabled.replication" (dict "subchart" "true" "context" $) }}
  93. Params:
  94. - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
  95. */}}
  96. {{- define "common.postgresql.values.enabled.replication" -}}
  97. {{- if .subchart -}}
  98. {{- printf "%v" .context.Values.postgresql.replication.enabled -}}
  99. {{- else -}}
  100. {{- printf "%v" .context.Values.replication.enabled -}}
  101. {{- end -}}
  102. {{- end -}}
  103. {{/*
  104. Auxiliary function to get the right value for the key replication.password.
  105. Usage:
  106. {{ include "common.postgresql.values.key.replicationPassword" (dict "subchart" "true" "context" $) }}
  107. Params:
  108. - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
  109. */}}
  110. {{- define "common.postgresql.values.key.replicationPassword" -}}
  111. {{- if .subchart -}}
  112. postgresql.replication.password
  113. {{- else -}}
  114. replication.password
  115. {{- end -}}
  116. {{- end -}}