_helpers.tpl 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Create a default fully qualified app name.
  4. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  5. */}}
  6. {{- define "halo.postgresql.fullname" -}}
  7. {{- include "common.names.dependency.fullname" (dict "chartName" "postgresql" "chartValues" .Values.postgresql "context" $) -}}
  8. {{- end -}}
  9. {{- define "halo.mysql.fullname" -}}
  10. {{- include "common.names.dependency.fullname" (dict "chartName" "mysql" "chartValues" .Values.mysql "context" $) -}}
  11. {{- end -}}
  12. {{/*
  13. Return the proper Halo image name
  14. */}}
  15. {{- define "halo.image" -}}
  16. {{- include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) -}}
  17. {{- end -}}
  18. {{/*
  19. Return the proper image name (for the init container volume-permissions image)
  20. */}}
  21. {{- define "halo.volumePermissions.image" -}}
  22. {{- include "common.images.image" ( dict "imageRoot" .Values.volumePermissions.image "global" .Values.global ) -}}
  23. {{- end -}}
  24. {{/*
  25. Return the proper Docker Image Registry Secret Names
  26. */}}
  27. {{- define "halo.imagePullSecrets" -}}
  28. {{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.volumePermissions.image) "global" .Values.global) -}}
  29. {{- end -}}
  30. {{/*
  31. Create the name of the service account to use
  32. */}}
  33. {{- define "halo.serviceAccountName" -}}
  34. {{- if .Values.serviceAccount.create -}}
  35. {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
  36. {{- else -}}
  37. {{ default "default" .Values.serviceAccount.name }}
  38. {{- end -}}
  39. {{- end -}}
  40. {{- define "halo.databasePlatform" -}}
  41. {{- if .Values.postgresql.enabled }}
  42. {{- printf "%s" "postgresql" -}}
  43. {{- else if .Values.mysql.enabled -}}
  44. {{- printf "%s" "mysql" -}}
  45. {{- else -}}
  46. {{- printf "%s" .Values.externalDatabase.platform -}}
  47. {{- end -}}
  48. {{- end -}}
  49. {{/*
  50. Return the Database Hostname
  51. */}}
  52. {{- define "halo.databaseHost" -}}
  53. {{- if .Values.postgresql.enabled }}
  54. {{- if eq .Values.postgresql.architecture "replication" }}
  55. {{- printf "%s-primary" (include "halo.postgresql.fullname" .) | trunc 63 | trimSuffix "-" -}}
  56. {{- else -}}
  57. {{- printf "%s" (include "halo.postgresql.fullname" .) -}}
  58. {{- end -}}
  59. {{- else if .Values.mysql.enabled }}
  60. {{- if eq .Values.mysql.architecture "replication" }}
  61. {{- printf "%s-primary" (include "halo.mysql.fullname" .) | trunc 63 | trimSuffix "-" -}}
  62. {{- else -}}
  63. {{- printf "%s" (include "halo.mysql.fullname" .) -}}
  64. {{- end -}}
  65. {{- else -}}
  66. {{- printf "%s" .Values.externalDatabase.host -}}
  67. {{- end -}}
  68. {{- end -}}
  69. {{/*
  70. Return the Database Port
  71. */}}
  72. {{- define "halo.databasePort" -}}
  73. {{- if .Values.postgresql.enabled }}
  74. {{- printf "%d" (default 5432 .Values.postgresql.primary.service.ports.postgresql | int) -}}
  75. {{- else if .Values.mysql.enabled }}
  76. {{- printf "%d" (default 3306 .Values.mysql.primary.service.ports.mysql | int) -}}
  77. {{- else -}}
  78. {{- printf "%d" (.Values.externalDatabase.port | int ) -}}
  79. {{- end -}}
  80. {{- end -}}
  81. {{/*
  82. Return the Database Name
  83. */}}
  84. {{- define "halo.databaseName" -}}
  85. {{- if .Values.postgresql.enabled }}
  86. {{- printf "%s" .Values.postgresql.auth.database -}}
  87. {{- else if .Values.mysql.enabled }}
  88. {{- printf "%s" .Values.mysql.auth.database -}}
  89. {{- else -}}
  90. {{- printf "%s" .Values.externalDatabase.database -}}
  91. {{- end -}}
  92. {{- end -}}
  93. {{/*
  94. Return the Database User
  95. */}}
  96. {{- define "halo.databaseUser" -}}
  97. {{- if .Values.postgresql.enabled }}
  98. {{- printf "%s" (default "halo" .Values.postgresql.auth.username) -}}
  99. {{- else if .Values.mysql.enabled }}
  100. {{- printf "%s" (default "halo" .Values.mysql.auth.username) -}}
  101. {{- else -}}
  102. {{- printf "%s" .Values.externalDatabase.user -}}
  103. {{- end -}}
  104. {{- end -}}
  105. {{/*
  106. Return the Database Secret Name
  107. */}}
  108. {{- define "halo.databaseSecretName" -}}
  109. {{- if .Values.postgresql.enabled }}
  110. {{- if .Values.postgresql.auth.existingSecret -}}
  111. {{- printf "%s" .Values.postgresql.auth.existingSecret -}}
  112. {{- else -}}
  113. {{- printf "%s" (include "halo.postgresql.fullname" .) -}}
  114. {{- end -}}
  115. {{- else if .Values.mysql.enabled }}
  116. {{- if .Values.mysql.auth.existingSecret -}}
  117. {{- printf "%s" .Values.mysql.auth.existingSecret -}}
  118. {{- else -}}
  119. {{- printf "%s" (include "halo.mysql.fullname" .) -}}
  120. {{- end -}}
  121. {{- else if .Values.externalDatabase.existingSecret -}}
  122. {{- include "common.tplvalues.render" (dict "value" .Values.externalDatabase.existingSecret "context" $) -}}
  123. {{- else -}}
  124. {{- printf "%s-externaldb" (include "common.names.fullname" .) -}}
  125. {{- end -}}
  126. {{- end -}}
  127. {{/*
  128. Return the Database Secret Name
  129. */}}
  130. {{- define "halo.databaseSecretKeyName" -}}
  131. {{- if .Values.postgresql.enabled }}
  132. {{- printf "password" -}}
  133. {{- else if .Values.mysql.enabled }}
  134. {{- printf "mysql-password" -}}
  135. {{- else -}}
  136. {{- printf "password" -}}
  137. {{- end -}}
  138. {{- end -}}
  139. {{/*
  140. Return the R2DBC URL
  141. */}}
  142. {{- define "halo.r2dbcUrl" -}}
  143. {{- printf "r2dbc:pool:%s://%s:%s/%s" (include "halo.databasePlatform" .) (include "halo.databaseHost" .) (include "halo.databasePort" .) (include "halo.databaseName" .) -}}
  144. {{- end -}}
  145. {{/*
  146. Return the Halo Secret Name
  147. */}}
  148. {{- define "halo.secretName" -}}
  149. {{- if .Values.existingSecret }}
  150. {{- printf "%s" .Values.existingSecret -}}
  151. {{- else -}}
  152. {{- printf "%s" (include "common.names.fullname" .) -}}
  153. {{- end -}}
  154. {{- end -}}
  155. {{/*
  156. Compile all warnings into a single message.
  157. */}}
  158. {{- define "halo.validateValues" -}}
  159. {{- $messages := list -}}
  160. {{- $messages := append $messages (include "halo.validateValues.database" .) -}}
  161. {{- $messages := without $messages "" -}}
  162. {{- $message := join "\n" $messages -}}
  163. {{- if $message -}}
  164. {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
  165. {{- end -}}
  166. {{- end -}}
  167. {{/* Validate values of Halo - Database */}}
  168. {{- define "halo.validateValues.database" -}}
  169. {{- if and (.Values.mysql.enabled) (.Values.postgresql.enabled) -}}
  170. halo: database
  171. You can only enable one database installation between PostgreSQL and MySQL.
  172. {{- else if and (not .Values.mysql.enabled) (not .Values.postgresql.enabled) (or (empty .Values.externalDatabase.host) (empty .Values.externalDatabase.port) (empty .Values.externalDatabase.user) (empty .Values.externalDatabase.password) (empty .Values.externalDatabase.database)) -}}
  173. halo: database
  174. You disable the PostgreSQL installation and the MySQL installation both, but you did not provide the required parameters
  175. to use an external database. To use an external database, please ensure you provide
  176. (at least) the following values:
  177. externalDatabase.host=DB_SERVER_HOST
  178. externalDatabase.port=DB_SERVER_PORT
  179. externalDatabase.user=DB_SERVER_USER
  180. externalDatabase.password=DB_SERVER_PASSWORD
  181. externalDatabase.database=DB_NAME
  182. {{- end -}}
  183. {{- end -}}