Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job template to deploy search #95

Merged
merged 11 commits into from
Mar 11, 2025
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 6.1.0

- Added a new job to re/build elasticsearch indices as a post-upgrade hook:
```yaml
mastodon:
hooks:
deploySearch:
```

# 6.0.3

- Updated the Mastodon version to v4.3.5
Expand Down
2 changes: 1 addition & 1 deletion Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time
# you make changes to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 6.0.3
version: 6.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
103 changes: 103 additions & 0 deletions templates/job-deploy-search.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{{- if and .Values.mastodon.hooks.deploySearch.enabled .Values.elasticsearch.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "mastodon.fullname" . }}-deploy-search
labels:
{{- include "mastodon.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
"helm.sh/hook-weight": "-2"
spec:
suspend: false
template:
metadata:
name: {{ include "mastodon.fullname" . }}-deploy-search
{{- with .Values.jobAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
restartPolicy: Never
{{- if (not .Values.mastodon.s3.enabled) }}
# ensure we run on the same node as the other rails components; only
# required when using PVCs that are ReadWriteOnce
{{- if or (eq "ReadWriteOnce" .Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" .Values.persistence.system.accessMode) }}
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/part-of
operator: In
values:
- rails
topologyKey: kubernetes.io/hostname
{{- end }}
volumes:
- name: assets
persistentVolumeClaim:
claimName: {{ template "mastodon.fullname" . }}-assets
- name: system
persistentVolumeClaim:
claimName: {{ template "mastodon.fullname" . }}-system
{{- end }}
containers:
- name: {{ include "mastodon.fullname" . }}-deploy-search
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.mastodon.hooks.deploySearch }}
{{- with .resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
command:
- bin/tootctl
- search
- deploy
{{- with .concurrency }}
- '--concurrency'
- {{ . | quote }}
{{- end }}
{{- if .resetChewy }}
- '--reset-chewy'
{{- end }}
{{- with .batchSize }}
- '--batch-size'
- {{ . | quote }}
{{- end }}
{{- with .only }}
{{- if not (has . (list "instances" "accounts" "tags" "statuses" "public_statuses")) -}}
{{ fail "mastodon.hooks.deploySearch.only: Value must be one of the following words: instances, accounts, tags, statuses, public_statuses"}}
{{- end }}
- '--only'
- {{ . | quote }}
{{- end }}
{{- end }}
envFrom:
- configMapRef:
name: {{ include "mastodon.fullname" . }}-env
- secretRef:
name: {{ template "mastodon.secretName" $ }}
env:
- name: "DB_PASS"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.postgresql.secretName" . }}
key: password
- name: "REDIS_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ template "mastodon.redis.secretName" . }}
key: redis-password
- name: "PORT"
value: {{ .Values.mastodon.web.port | quote }}
{{- if (not .Values.mastodon.s3.enabled) }}
volumeMounts:
- name: assets
mountPath: /opt/mastodon/public/assets
- name: system
mountPath: /opt/mastodon/public/system
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ mastodon:
# Whether to perform DB migrations on `helm upgrade`.
dbMigrate:
enabled: true

# WARNING: deploySearch is potentially a very expensive job!
# Only enable this once at a time, when you deploy elasticsearch or when
# the upgrade notes for a new mastodon version request rebuilding search.
# Recommended use is via `-f mastodon.hooks.deploySearch.enabled=true`
# to ensure the job is only dispatched for a single upgrade when required.
# This job may take days to run on very large instances. Even small
# instances may take long enough to trigger helm's completion timeout, so
# DO NOT PANIC if helm complains; simply verify the job is still running.
#
# Builds or rebuilds the elasticsearch indices via `tootctl deploy search`
# with timing hooks to ensure the job runs immediately after install/upgrade
# and will be restarted if another, corrective upgrade is triggered.
# Please check the tootctl documentation and upgrade notes to pick values.
#
# NOTE: The resource stanza set below is intentionally very conservative.
# Consider assigning a liberal chunk of your cluster's typical headroom.
deploySearch:
enabled: false
resetChewy: true
# one index name. Possible values: instances, accounts, tags, statuses, public_statuses
only: ""
concurrency: 5
resources: # this accepts any keys in a full container resources stanza.
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 500m

# Upload website assets to S3 before deploying using rclone.
# Whenever there is an update to Mastodon, sometimes there are assets files
# that are renamed. As the pods are getting redeployed, and old/new pods are
Expand All @@ -59,6 +89,7 @@ mastodon:
env: {}
# Custom labels to add to kubernetes resources
#labels:
# -- deploy search to elastsicsearch. Requires .elasticsearch.enabled = true
cron:
# -- run `tootctl media remove` every week
removeMedia:
Expand Down