deployment-sidekiq.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. {{- $context := . }}
  2. {{- range .Values.mastodon.sidekiq.workers }}
  3. ---
  4. apiVersion: apps/v1
  5. kind: Deployment
  6. metadata:
  7. name: {{ include "mastodon.fullname" $context }}-sidekiq-{{ .name }}
  8. labels:
  9. {{- include "mastodon.labels" $context | nindent 4 }}
  10. {{- with $context.Values.mastodon.sidekiq.labels }}
  11. {{- toYaml . | nindent 4 }}
  12. {{- end }}
  13. app.kubernetes.io/component: sidekiq-{{ .name }}
  14. app.kubernetes.io/part-of: rails
  15. annotations:
  16. {{- with $context.Values.deploymentAnnotations }}
  17. {{- toYaml . | nindent 4 }}
  18. {{- end }}
  19. {{- with $context.Values.mastodon.sidekiq.annotations }}
  20. {{- toYaml . | nindent 4 }}
  21. {{- end }}
  22. spec:
  23. {{- if (has "scheduler" .queues) }}
  24. {{- if (gt (int .replicas) 1) }}
  25. {{ fail "The scheduler queue should never have more than 1 replicas" }}
  26. {{- end }}
  27. {{- end }}
  28. {{- if $context.Values.mastodon.sidekiq.updateStrategy }}
  29. strategy: {{- toYaml $context.Values.mastodon.sidekiq.updateStrategy | nindent 4 }}
  30. {{- end }}
  31. replicas: {{ .replicas }}
  32. {{- if (ne (toString $context.Values.mastodon.revisionHistoryLimit) "<nil>") }}
  33. revisionHistoryLimit: {{ $context.Values.mastodon.revisionHistoryLimit }}
  34. {{- end }}
  35. selector:
  36. matchLabels:
  37. {{- include "mastodon.selectorLabels" $context | nindent 6 }}
  38. app.kubernetes.io/component: sidekiq-{{ .name }}
  39. app.kubernetes.io/part-of: rails
  40. template:
  41. metadata:
  42. annotations:
  43. {{- with $context.Values.podAnnotations }}
  44. {{- toYaml . | nindent 8 }}
  45. {{- end }}
  46. {{- with $context.Values.mastodon.sidekiq.podAnnotations }}
  47. {{- toYaml . | nindent 8 }}
  48. {{- end }}
  49. # roll the pods to pick up any db migrations or other changes
  50. {{- include "mastodon.rollingPodAnnotations" $context | nindent 8 }}
  51. checksum/config-secrets-smtp: {{ include ( print $.Template.BasePath "/secret-smtp.yaml" ) $context | sha256sum | quote }}
  52. labels:
  53. {{- include "mastodon.globalLabels" $context | nindent 8 }}
  54. {{- include "mastodon.selectorLabels" $context | nindent 8 }}
  55. {{- include "mastodon.statsdExporterLabels" $context | nindent 8 }}
  56. {{- with $context.Values.mastodon.sidekiq.podLabels }}
  57. {{- toYaml . | nindent 8 }}
  58. {{- end }}
  59. app.kubernetes.io/component: sidekiq-{{ .name }}
  60. app.kubernetes.io/part-of: rails
  61. spec:
  62. {{- with $context.Values.imagePullSecrets }}
  63. imagePullSecrets:
  64. {{- toYaml . | nindent 8 }}
  65. {{- end }}
  66. serviceAccountName: {{ include "mastodon.serviceAccountName" $context }}
  67. {{- with (default $context.Values.podSecurityContext $context.Values.mastodon.sidekiq.podSecurityContext) }}
  68. securityContext:
  69. {{- toYaml . | nindent 8 }}
  70. {{- end }}
  71. {{- with (default (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) .affinity) }}
  72. affinity:
  73. {{- toYaml . | nindent 8 }}
  74. {{- end }}
  75. {{- with (default (default $context.Values.topologySpreadConstraints $context.Values.mastodon.sidekiq.topologySpreadConstraints) .topologySpreadConstraints) }}
  76. topologySpreadConstraints:
  77. {{- toYaml . | nindent 8 }}
  78. {{- end }}
  79. volumes:
  80. {{- if (not $context.Values.mastodon.s3.enabled) }}
  81. - name: assets
  82. persistentVolumeClaim:
  83. claimName: {{ template "mastodon.pvc.assets" $context }}
  84. - name: system
  85. persistentVolumeClaim:
  86. claimName: {{ template "mastodon.pvc.system" $context }}
  87. {{- end }}
  88. {{- include "mastodon.statsdExporterVolume" $ | indent 8 }}
  89. {{- if dig "customDatabaseConfigYml" "configMapRef" "name" false . }}
  90. - name: config-database-yml
  91. configMap:
  92. name: {{ .customDatabaseConfigYml.configMapRef.name }}
  93. {{- end }}
  94. {{- with $context.Values.volumes }}
  95. {{- toYaml . | nindent 8 }}
  96. {{- end }}
  97. containers:
  98. - name: {{ $context.Chart.Name }}
  99. {{- with $context.Values.mastodon.sidekiq.securityContext | default $context.Values.securityContext }}
  100. securityContext:
  101. {{- toYaml . | nindent 12 }}
  102. {{- end }}
  103. image: "{{ coalesce (dig "image" "repository" false .) $context.Values.image.repository }}:{{ coalesce (dig "image" "tag" false .) $context.Values.image.tag $context.Chart.AppVersion }}"
  104. imagePullPolicy: {{ $context.Values.image.pullPolicy }}
  105. command:
  106. - bundle
  107. - exec
  108. - sidekiq
  109. - -c
  110. - {{ .concurrency | quote }}
  111. {{- range .queues }}
  112. - -q
  113. - {{ . | quote }}
  114. {{- end }}
  115. envFrom:
  116. - configMapRef:
  117. name: {{ include "mastodon.fullname" $context }}-env
  118. - secretRef:
  119. name: {{ template "mastodon.secretName" $context }}
  120. {{- if $context.Values.mastodon.extraEnvFrom }}
  121. - configMapRef:
  122. name: {{ $context.Values.mastodon.extraEnvFrom }}
  123. {{- end}}
  124. env:
  125. - name: "DB_PASS"
  126. valueFrom:
  127. secretKeyRef:
  128. name: {{ template "mastodon.postgresql.secretName" $context }}
  129. key: password
  130. {{- if $context.Values.postgresql.readReplica.auth.existingSecret }}
  131. - name: "REPLICA_DB_PASS"
  132. valueFrom:
  133. secretKeyRef:
  134. name: {{ $context.Values.postgresql.readReplica.auth.existingSecret }}
  135. key: password
  136. {{- end }}
  137. - name: "REDIS_PASSWORD"
  138. valueFrom:
  139. secretKeyRef:
  140. name: {{ template "mastodon.redis.secretName" $context }}
  141. key: redis-password
  142. {{- if and $context.Values.redis.sidekiq.enabled $context.Values.redis.sidekiq.auth.existingSecret }}
  143. - name: "SIDEKIQ_REDIS_PASSWORD"
  144. valueFrom:
  145. secretKeyRef:
  146. name: {{ template "mastodon.redis.sidekiq.secretName" $context }}
  147. key: redis-password
  148. {{- end }}
  149. {{- if and $context.Values.redis.cache.enabled $context.Values.redis.cache.auth.existingSecret }}
  150. - name: "CACHE_REDIS_PASSWORD"
  151. valueFrom:
  152. secretKeyRef:
  153. name: {{ template "mastodon.redis.cache.secretName" $context }}
  154. key: redis-password
  155. {{- end }}
  156. {{- if and $context.Values.elasticsearch.existingSecret (or $context.Values.elasticsearch.enabled $context.Values.elasticsearch.hostname) }}
  157. - name: "ES_PASS"
  158. valueFrom:
  159. secretKeyRef:
  160. name: {{ $context.Values.elasticsearch.existingSecret }}
  161. key: password
  162. {{- end }}
  163. - name: "SMTP_LOGIN"
  164. valueFrom:
  165. secretKeyRef:
  166. name: {{ include "mastodon.smtp.secretName" $context }}
  167. key: login
  168. optional: true
  169. - name: "SMTP_PASSWORD"
  170. valueFrom:
  171. secretKeyRef:
  172. name: {{ include "mastodon.smtp.secretName" $context }}
  173. key: password
  174. optional: true
  175. {{- if (and $context.Values.mastodon.s3.enabled $context.Values.mastodon.s3.existingSecret) }}
  176. - name: "AWS_SECRET_ACCESS_KEY"
  177. valueFrom:
  178. secretKeyRef:
  179. name: {{ $context.Values.mastodon.s3.existingSecret }}
  180. key: AWS_SECRET_ACCESS_KEY
  181. - name: "AWS_ACCESS_KEY_ID"
  182. valueFrom:
  183. secretKeyRef:
  184. name: {{ $context.Values.mastodon.s3.existingSecret }}
  185. key: AWS_ACCESS_KEY_ID
  186. {{- end }}
  187. {{- if and $context.Values.mastodon.deepl.enabled }}
  188. - name: "DEEPL_API_KEY"
  189. valueFrom:
  190. secretKeyRef:
  191. name: {{ $context.Values.mastodon.deepl.apiKeySecretRef.name }}
  192. key: {{ $context.Values.mastodon.deepl.apiKeySecretRef.key }}
  193. {{- end }}
  194. {{- if and $context.Values.mastodon.cacheBuster.enabled $context.Values.mastodon.cacheBuster.authToken.existingSecret }}
  195. - name: CACHE_BUSTER_SECRET
  196. valueFrom:
  197. secretKeyRef:
  198. name: {{ $context.Values.mastodon.cacheBuster.authToken.existingSecret }}
  199. key: password
  200. {{- end }}
  201. {{- if or $context.Values.mastodon.sidekiq.otel.enabled (and $context.Values.mastodon.otel.enabled (ne $context.Values.mastodon.sidekiq.otel.enabled false)) }}
  202. - name: OTEL_EXPORTER_OTLP_ENDPOINT
  203. value: {{ coalesce $context.Values.mastodon.sidekiq.otel.endpointUri $context.Values.mastodon.otel.endpointUri }}
  204. - name: OTEL_SERVICE_NAME_PREFIX
  205. value: {{ coalesce $context.Values.mastodon.sidekiq.otel.namePrefix $context.Values.mastodon.otel.namePrefix }}
  206. - name: OTEL_SERVICE_NAME_SEPARATOR
  207. value: "{{ coalesce $context.Values.mastodon.sidekiq.otel.nameSeparator $context.Values.mastodon.otel.nameSeparator }}"
  208. {{- end }}
  209. volumeMounts:
  210. {{- if (not $context.Values.mastodon.s3.enabled) }}
  211. - name: assets
  212. mountPath: /opt/mastodon/public/assets
  213. - name: system
  214. mountPath: /opt/mastodon/public/system
  215. {{- end }}
  216. {{- if dig "customDatabaseConfigYml" "configMapRef" "name" false . }}
  217. - name: config-database-yml
  218. mountPath: /opt/mastodon/config/database.yml
  219. subPath: {{ .customDatabaseConfigYml.configMapRef.key }}
  220. {{- end }}
  221. {{- with $context.Values.volumeMounts }}
  222. {{- toYaml . | nindent 12 }}
  223. {{- end }}
  224. {{- if $context.Values.mastodon.sidekiq.readinessProbe.enabled }}
  225. readinessProbe:
  226. failureThreshold: {{ default 10 $context.Values.mastodon.sidekiq.readinessProbe.failureThreshold }}
  227. exec:
  228. command:
  229. - cat
  230. - {{ required "A valid sidekiq readiness path is required." $context.Values.mastodon.sidekiq.readinessProbe.path }}
  231. initialDelaySeconds: {{ default 10 $context.Values.mastodon.sidekiq.readinessProbe.initialDelaySeconds }}
  232. periodSeconds: {{ default 2 $context.Values.mastodon.sidekiq.readinessProbe.periodSeconds }}
  233. successThreshold: {{ default 1 $context.Values.mastodon.sidekiq.readinessProbe.successThreshold }}
  234. timeoutSeconds: {{ default 1 $context.Values.mastodon.sidekiq.readinessProbe.timeoutSeconds }}
  235. {{- end }}
  236. resources:
  237. {{- toYaml (default (default $context.Values.resources $context.Values.mastodon.sidekiq.resources) .resources) | nindent 12 }}
  238. {{- include "mastodon.statsdExporterContainer" $ | indent 8 }}
  239. {{- with $context.Values.nodeSelector }}
  240. nodeSelector:
  241. {{- toYaml . | nindent 8 }}
  242. {{- end }}
  243. {{- with $context.Values.tolerations }}
  244. tolerations:
  245. {{- toYaml . | nindent 8 }}
  246. {{- end }}
  247. {{- end }}