_helpers.tpl 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "mastodon.name" -}}
  6. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
  7. {{- end }}
  8. {{/*
  9. Create a default fully qualified app name.
  10. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  11. If release name contains chart name it will be used as a full name.
  12. */}}
  13. {{- define "mastodon.fullname" -}}
  14. {{- if .Values.fullnameOverride }}
  15. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
  16. {{- else }}
  17. {{- $name := default .Chart.Name .Values.nameOverride }}
  18. {{- if contains $name .Release.Name }}
  19. {{- .Release.Name | trunc 63 | trimSuffix "-" }}
  20. {{- else }}
  21. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
  22. {{- end }}
  23. {{- end }}
  24. {{- end }}
  25. {{/*
  26. Create chart name and version as used by the chart label.
  27. */}}
  28. {{- define "mastodon.chart" -}}
  29. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
  30. {{- end }}
  31. {{/*
  32. Labels added on every Mastodon resource
  33. */}}
  34. {{- define "mastodon.globalLabels" -}}
  35. {{- range $k, $v := .Values.mastodon.labels }}
  36. {{ $k }}: {{ quote $v }}
  37. {{- end -}}
  38. {{- end }}
  39. {{/*
  40. Common labels
  41. */}}
  42. {{- define "mastodon.labels" -}}
  43. helm.sh/chart: {{ include "mastodon.chart" . }}
  44. {{ include "mastodon.selectorLabels" . }}
  45. {{ include "mastodon.globalLabels" . }}
  46. {{- if .Values.image.tag }}
  47. app.kubernetes.io/version: {{ regexReplaceAll "@(\\w+:\\w{0,7})\\w*" .Values.image.tag "@${1}" | quote }}
  48. {{- else if .Chart.AppVersion }}
  49. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  50. {{- end }}
  51. app.kubernetes.io/managed-by: {{ .Release.Service }}
  52. {{- end }}
  53. {{/*
  54. Selector labels
  55. */}}
  56. {{- define "mastodon.selectorLabels" -}}
  57. app.kubernetes.io/name: {{ include "mastodon.name" . }}
  58. app.kubernetes.io/instance: {{ .Release.Name }}
  59. {{- end }}
  60. {{/*
  61. Rolling pod annotations
  62. */}}
  63. {{- define "mastodon.rollingPodAnnotations" -}}
  64. {{- if .Values.revisionPodAnnotation }}
  65. rollme: {{ .Release.Revision | quote }}
  66. {{- end }}
  67. checksum/config-secrets: {{ include ( print $.Template.BasePath "/secrets.yaml" ) . | sha256sum | quote }}
  68. checksum/config-configmap: {{ include ( print $.Template.BasePath "/configmap-env.yaml" ) . | sha256sum | quote }}
  69. {{- end }}
  70. {{/*
  71. Create the name of the service account to use
  72. */}}
  73. {{- define "mastodon.serviceAccountName" -}}
  74. {{- if .Values.serviceAccount.create }}
  75. {{- default (include "mastodon.fullname" .) .Values.serviceAccount.name }}
  76. {{- else }}
  77. {{- default "default" .Values.serviceAccount.name }}
  78. {{- end }}
  79. {{- end }}
  80. {{/*
  81. Create the name of the assets persistent volume to use
  82. */}}
  83. {{- define "mastodon.pvc.assets" -}}
  84. {{- if .Values.mastodon.persistence.assets.existingClaim }}
  85. {{- printf "%s" (tpl .Values.mastodon.persistence.assets.existingClaim $) -}}
  86. {{- else -}}
  87. {{- printf "%s-assets" (include "mastodon.fullname" .) -}}
  88. {{- end -}}
  89. {{- end -}}
  90. {{/*
  91. Create the name of the system persistent volume to use
  92. */}}
  93. {{- define "mastodon.pvc.system" -}}
  94. {{- if .Values.mastodon.persistence.system.existingClaim }}
  95. {{- printf "%s" (tpl .Values.mastodon.persistence.system.existingClaim $) -}}
  96. {{- else -}}
  97. {{- printf "%s-system" (include "mastodon.fullname" .) -}}
  98. {{- end -}}
  99. {{- end -}}
  100. {{/*
  101. Create a default fully qualified name for dependent services.
  102. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  103. */}}
  104. {{- define "mastodon.elasticsearch.fullname" -}}
  105. {{- printf "%s-%s" .Release.Name "elasticsearch" | trunc 63 | trimSuffix "-" -}}
  106. {{- end -}}
  107. {{- define "mastodon.redis.fullname" -}}
  108. {{- printf "%s-%s" .Release.Name "redis" | trunc 63 | trimSuffix "-" -}}
  109. {{- end -}}
  110. {{- define "mastodon.postgresql.fullname" -}}
  111. {{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
  112. {{- end -}}
  113. {{/*
  114. Establish which values we will use for remote connections
  115. */}}
  116. {{- define "mastodon.postgres.host" -}}
  117. {{- if .Values.postgresql.enabled }}
  118. {{- printf "%s" (include "mastodon.postgresql.fullname" .) -}}
  119. {{- else }}
  120. {{- printf "%s" (required "When the postgresql chart is disabled .Values.postgresql.postgresqlHostname is required" .Values.postgresql.postgresqlHostname) -}}
  121. {{- end }}
  122. {{- end }}
  123. {{- define "mastodon.postgres.port" -}}
  124. {{- if .Values.postgresql.enabled }}
  125. {{- printf "%d" 5432 | int | quote -}}
  126. {{- else }}
  127. {{- printf "%d" | default 5432 .Values.postgresql.postgresqlPort | int | quote -}}
  128. {{- end }}
  129. {{- end }}
  130. {{/*
  131. Establish which values we will use for direct remote DB connections
  132. */}}
  133. {{- define "mastodon.postgres.direct.host" -}}
  134. {{- if .Values.postgresql.direct.hostname }}
  135. {{- printf "%s" .Values.postgresql.direct.hostname -}}
  136. {{- else }}
  137. {{- printf "%s" (include "mastodon.postgres.host" .) -}}
  138. {{- end }}
  139. {{- end }}
  140. {{- define "mastodon.postgres.direct.port" -}}
  141. {{- if .Values.postgresql.direct.port }}
  142. {{- printf "%d" (int .Values.postgresql.direct.port) | quote -}}
  143. {{- else }}
  144. {{- printf "%s" (include "mastodon.postgres.port" .) -}}
  145. {{- end }}
  146. {{- end }}
  147. {{- define "mastodon.postgres.direct.database" -}}
  148. {{- if .Values.postgresql.direct.database }}
  149. {{- printf "%s" .Values.postgresql.direct.database -}}
  150. {{- else }}
  151. {{- printf "%s" .Values.postgresql.auth.database -}}
  152. {{- end }}
  153. {{- end }}
  154. {{- define "mastodon.redis.host" -}}
  155. {{- if .Values.redis.enabled }}
  156. {{- printf "%s-%s" (include "mastodon.redis.fullname" .) "master" -}}
  157. {{- else }}
  158. {{- printf "%s" (required "When the redis chart is disabled .Values.redis.hostname is required" .Values.redis.hostname) -}}
  159. {{- end }}
  160. {{- end }}
  161. {{/*
  162. Get the mastodon secret.
  163. */}}
  164. {{- define "mastodon.secretName" -}}
  165. {{- if .Values.mastodon.secrets.existingSecret }}
  166. {{- printf "%s" (tpl .Values.mastodon.secrets.existingSecret $) -}}
  167. {{- else -}}
  168. {{- printf "%s" (include "mastodon.fullname" .) -}}
  169. {{- end -}}
  170. {{- end -}}
  171. {{/*
  172. Get the smtp secret.
  173. */}}
  174. {{- define "mastodon.smtp.secretName" -}}
  175. {{- if .Values.mastodon.smtp.existingSecret }}
  176. {{- printf "%s" (tpl .Values.mastodon.smtp.existingSecret $) -}}
  177. {{- else -}}
  178. {{- printf "%s-smtp" (include "mastodon.fullname" .) -}}
  179. {{- end -}}
  180. {{- end -}}
  181. {{/*
  182. Get the postgresql secret.
  183. */}}
  184. {{- define "mastodon.postgresql.secretName" -}}
  185. {{- if (and (or .Values.postgresql.enabled .Values.postgresql.postgresqlHostname) .Values.postgresql.auth.existingSecret) }}
  186. {{- printf "%s" (tpl .Values.postgresql.auth.existingSecret $) -}}
  187. {{- else if .Values.postgresql.enabled -}}
  188. {{- printf "%s-postgresql" (tpl .Release.Name $) -}}
  189. {{- else -}}
  190. {{- printf "%s" (include "mastodon.fullname" .) -}}
  191. {{- end -}}
  192. {{- end -}}
  193. {{/*
  194. Get the redis secret.
  195. */}}
  196. {{- define "mastodon.redis.secretName" -}}
  197. {{- if .Values.redis.auth.existingSecret }}
  198. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  199. {{- else if .Values.redis.existingSecret }}
  200. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  201. {{- else if .Values.redis.enabled -}}
  202. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  203. {{- else -}}
  204. {{- printf "%s-redis" (include "mastodon.fullname" .) -}}
  205. {{- end -}}
  206. {{- end -}}
  207. {{/*
  208. Get the redis secret (sidekiq).
  209. */}}
  210. {{- define "mastodon.redis.sidekiq.secretName" -}}
  211. {{- if .Values.redis.sidekiq.auth.existingSecret }}
  212. {{- printf "%s" (tpl .Values.redis.sidekiq.auth.existingSecret $) -}}
  213. {{- else if .Values.redis.auth.existingSecret }}
  214. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  215. {{- else if .Values.redis.existingSecret }}
  216. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  217. {{- else -}}
  218. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  219. {{- end -}}
  220. {{- end -}}
  221. {{/*
  222. Get the redis secret (cache).
  223. */}}
  224. {{- define "mastodon.redis.cache.secretName" -}}
  225. {{- if .Values.redis.cache.auth.existingSecret }}
  226. {{- printf "%s" (tpl .Values.redis.cache.auth.existingSecret $) -}}
  227. {{- else if .Values.redis.auth.existingSecret }}
  228. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  229. {{- else if .Values.redis.existingSecret }}
  230. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  231. {{- else -}}
  232. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  233. {{- end -}}
  234. {{- end -}}
  235. {{/*
  236. Return true if a mastodon secret object should be created
  237. */}}
  238. {{- define "mastodon.createSecret" -}}
  239. {{- if (or
  240. (and .Values.mastodon.s3.enabled (not .Values.mastodon.s3.existingSecret))
  241. (not .Values.mastodon.secrets.existingSecret )
  242. (and (not .Values.postgresql.enabled) (not .Values.postgresql.auth.existingSecret))
  243. ) -}}
  244. {{- true -}}
  245. {{- end -}}
  246. {{- end -}}
  247. {{/*
  248. Full hostname for a custom Elasticsearch cluster
  249. */}}
  250. {{- define "mastodon.elasticsearch.fullHostname" -}}
  251. {{- if not .Values.elasticsearch.enabled }}
  252. {{- if .Values.elasticsearch.tls }}
  253. {{- printf "https://%s" (tpl .Values.elasticsearch.hostname $) -}}
  254. {{- else -}}
  255. {{- printf "%s" (tpl .Values.elasticsearch.hostname $) -}}
  256. {{- end }}
  257. {{- end -}}
  258. {{- end -}}