_helpers.tpl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 .Chart.AppVersion }}
  47. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  48. {{- end }}
  49. app.kubernetes.io/managed-by: {{ .Release.Service }}
  50. {{- end }}
  51. {{/*
  52. Selector labels
  53. */}}
  54. {{- define "mastodon.selectorLabels" -}}
  55. app.kubernetes.io/name: {{ include "mastodon.name" . }}
  56. app.kubernetes.io/instance: {{ .Release.Name }}
  57. {{- end }}
  58. {{/*
  59. Rolling pod annotations
  60. */}}
  61. {{- define "mastodon.rollingPodAnnotations" -}}
  62. {{- if .Values.revisionPodAnnotation }}
  63. rollme: {{ .Release.Revision | quote }}
  64. {{- end }}
  65. checksum/config-secrets: {{ include ( print $.Template.BasePath "/secrets.yaml" ) . | sha256sum | quote }}
  66. checksum/config-configmap: {{ include ( print $.Template.BasePath "/configmap-env.yaml" ) . | sha256sum | quote }}
  67. {{- end }}
  68. {{/*
  69. Create the name of the service account to use
  70. */}}
  71. {{- define "mastodon.serviceAccountName" -}}
  72. {{- if .Values.serviceAccount.create }}
  73. {{- default (include "mastodon.fullname" .) .Values.serviceAccount.name }}
  74. {{- else }}
  75. {{- default "default" .Values.serviceAccount.name }}
  76. {{- end }}
  77. {{- end }}
  78. {{/*
  79. Create the name of the assets persistent volume to use
  80. */}}
  81. {{- define "mastodon.pvc.assets" -}}
  82. {{- if .Values.mastodon.persistence.assets.existingClaim }}
  83. {{- printf "%s" (tpl .Values.mastodon.persistence.assets.existingClaim $) -}}
  84. {{- else -}}
  85. {{- printf "%s-assets" (include "common.names.fullname" .) -}}
  86. {{- end -}}
  87. {{- end -}}
  88. {{/*
  89. Create the name of the system persistent volume to use
  90. */}}
  91. {{- define "mastodon.pvc.system" -}}
  92. {{- if .Values.mastodon.persistence.system.existingClaim }}
  93. {{- printf "%s" (tpl .Values.mastodon.persistence.system.existingClaim $) -}}
  94. {{- else -}}
  95. {{- printf "%s-system" (include "common.names.fullname" .) -}}
  96. {{- end -}}
  97. {{- end -}}
  98. {{/*
  99. Create a default fully qualified name for dependent services.
  100. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  101. */}}
  102. {{- define "mastodon.elasticsearch.fullname" -}}
  103. {{- printf "%s-%s" .Release.Name "elasticsearch" | trunc 63 | trimSuffix "-" -}}
  104. {{- end -}}
  105. {{- define "mastodon.redis.fullname" -}}
  106. {{- printf "%s-%s" .Release.Name "redis" | trunc 63 | trimSuffix "-" -}}
  107. {{- end -}}
  108. {{- define "mastodon.postgresql.fullname" -}}
  109. {{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
  110. {{- end -}}
  111. {{/*
  112. Get the mastodon secret.
  113. */}}
  114. {{- define "mastodon.secretName" -}}
  115. {{- if .Values.mastodon.secrets.existingSecret }}
  116. {{- printf "%s" (tpl .Values.mastodon.secrets.existingSecret $) -}}
  117. {{- else -}}
  118. {{- printf "%s" (include "mastodon.fullname" .) -}}
  119. {{- end -}}
  120. {{- end -}}
  121. {{/*
  122. Get the smtp secret.
  123. */}}
  124. {{- define "mastodon.smtp.secretName" -}}
  125. {{- if .Values.mastodon.smtp.existingSecret }}
  126. {{- printf "%s" (tpl .Values.mastodon.smtp.existingSecret $) -}}
  127. {{- else -}}
  128. {{- printf "%s-smtp" (include "mastodon.fullname" .) -}}
  129. {{- end -}}
  130. {{- end -}}
  131. {{/*
  132. Get the postgresql secret.
  133. */}}
  134. {{- define "mastodon.postgresql.secretName" -}}
  135. {{- if (and (or .Values.postgresql.enabled .Values.postgresql.postgresqlHostname) .Values.postgresql.auth.existingSecret) }}
  136. {{- printf "%s" (tpl .Values.postgresql.auth.existingSecret $) -}}
  137. {{- else if .Values.postgresql.enabled -}}
  138. {{- printf "%s-postgresql" (tpl .Release.Name $) -}}
  139. {{- else -}}
  140. {{- printf "%s" (include "mastodon.fullname" .) -}}
  141. {{- end -}}
  142. {{- end -}}
  143. {{/*
  144. Get the redis secret.
  145. */}}
  146. {{- define "mastodon.redis.secretName" -}}
  147. {{- if .Values.redis.auth.existingSecret }}
  148. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  149. {{- else if .Values.redis.existingSecret }}
  150. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  151. {{- else if .Values.redis.enabled -}}
  152. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  153. {{- else -}}
  154. {{- printf "%s-redis" (include "mastodon.fullname" .) -}}
  155. {{- end -}}
  156. {{- end -}}
  157. {{/*
  158. Get the redis secret (sidekiq).
  159. */}}
  160. {{- define "mastodon.redis.sidekiq.secretName" -}}
  161. {{- if .Values.redis.sidekiq.auth.existingSecret }}
  162. {{- printf "%s" (tpl .Values.redis.sidekiq.auth.existingSecret $) -}}
  163. {{- else if .Values.redis.auth.existingSecret }}
  164. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  165. {{- else if .Values.redis.existingSecret }}
  166. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  167. {{- else -}}
  168. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  169. {{- end -}}
  170. {{- end -}}
  171. {{/*
  172. Get the redis secret (cache).
  173. */}}
  174. {{- define "mastodon.redis.cache.secretName" -}}
  175. {{- if .Values.redis.cache.auth.existingSecret }}
  176. {{- printf "%s" (tpl .Values.redis.cache.auth.existingSecret $) -}}
  177. {{- else if .Values.redis.auth.existingSecret }}
  178. {{- printf "%s" (tpl .Values.redis.auth.existingSecret $) -}}
  179. {{- else if .Values.redis.existingSecret }}
  180. {{- printf "%s" (tpl .Values.redis.existingSecret $) -}}
  181. {{- else -}}
  182. {{- printf "%s-redis" (tpl .Release.Name $) -}}
  183. {{- end -}}
  184. {{- end -}}
  185. {{/*
  186. Return true if a mastodon secret object should be created
  187. */}}
  188. {{- define "mastodon.createSecret" -}}
  189. {{- if (or
  190. (and .Values.mastodon.s3.enabled (not .Values.mastodon.s3.existingSecret))
  191. (not .Values.mastodon.secrets.existingSecret )
  192. (and (not .Values.postgresql.enabled) (not .Values.postgresql.auth.existingSecret))
  193. ) -}}
  194. {{- true -}}
  195. {{- end -}}
  196. {{- end -}}
  197. {{/*
  198. Find highest number of needed database connections to set DB_POOL variable
  199. */}}
  200. {{- define "mastodon.maxDbPool" -}}
  201. {{/* Default MAX_THREADS for Puma is 5 */}}
  202. {{- $poolSize := 5 }}
  203. {{- range .Values.mastodon.sidekiq.workers }}
  204. {{- $poolSize = max $poolSize .concurrency }}
  205. {{- end }}
  206. {{- $poolSize | quote }}
  207. {{- end }}
  208. {{/*
  209. Full hostname for a custom Elasticsearch cluster
  210. */}}
  211. {{- define "mastodon.elasticsearch.fullHostname" -}}
  212. {{- if not .Values.elasticsearch.enabled }}
  213. {{- if .Values.elasticsearch.tls }}
  214. {{- printf "https://%s" (tpl .Values.elasticsearch.hostname $) -}}
  215. {{- else -}}
  216. {{- printf "%s" (tpl .Values.elasticsearch.hostname $) -}}
  217. {{- end }}
  218. {{- end -}}
  219. {{- end -}}