_postgresql.tpl 4.9 KB

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