Skip to content

Commit b20acd7

Browse files
committed
Added pod affinity if the default ReadWriteOnce is used.
If `accessMode` `ReadWriteOnce` is used, then the volume can only be accessed in a write mode from a single node. This means that all pods which require write access to the volume need to be co-located to the same node. Failing that typically leads to a difficult to untangle locked volume mount situation where containers are stuck in `ContainerCreating`. This change adds the necessary pod affinities if the related access modes are set in the `values.yaml`.
1 parent ae892d5 commit b20acd7

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

templates/deployment-sidekiq.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,26 @@ spec:
4545
securityContext:
4646
{{- toYaml . | nindent 8 }}
4747
{{- end }}
48-
{{- with (default (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) .affinity) }}
4948
affinity:
50-
{{- toYaml . | nindent 8 }}
51-
{{- end }}
49+
{{- if (not $context.Values.mastodon.s3.enabled) }}
50+
{{- if not (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity).podAffinity }}
51+
{{- if or (eq "ReadWriteOnce" $context.Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" $context.Values.mastodon.persistence.system.accessMode) }}
52+
# the pods need to end up to the same node for ReadWriteOnce
53+
podAffinity:
54+
requiredDuringSchedulingIgnoredDuringExecution:
55+
- labelSelector:
56+
matchExpressions:
57+
- key: app.kubernetes.io/part-of
58+
operator: In
59+
values:
60+
- rails
61+
topologyKey: kubernetes.io/hostname
62+
{{- end }}
63+
{{- end }}
64+
{{- end }}
65+
{{- with (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) }}
66+
{{- toYaml . | nindent 8 }}
67+
{{- end }}
5268
{{- if (not $context.Values.mastodon.s3.enabled) }}
5369
volumes:
5470
- name: assets

templates/deployment-web.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,26 @@ spec:
118118
nodeSelector:
119119
{{- toYaml . | nindent 8 }}
120120
{{- end }}
121-
{{- with (default .Values.affinity .Values.mastodon.web.affinity) }}
122121
affinity:
123-
{{- toYaml . | nindent 8 }}
124-
{{- end }}
122+
{{- if (not .Values.mastodon.s3.enabled) }}
123+
{{- if not (default .Values.affinity .Values.mastodon.web.affinity).podAffinity }}
124+
{{- if or (eq "ReadWriteOnce" .Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" .Values.mastodon.persistence.system.accessMode) }}
125+
# the pods need to end up to the same node for ReadWriteOnce
126+
podAffinity:
127+
requiredDuringSchedulingIgnoredDuringExecution:
128+
- labelSelector:
129+
matchExpressions:
130+
- key: app.kubernetes.io/part-of
131+
operator: In
132+
values:
133+
- rails
134+
topologyKey: kubernetes.io/hostname
135+
{{- end }}
136+
{{- end }}
137+
{{- end }}
138+
{{- with (default .Values.affinity .Values.mastodon.web.affinity) }}
139+
{{- toYaml . | nindent 8 }}
140+
{{- end }}
125141
{{- with .Values.tolerations }}
126142
tolerations:
127143
{{- toYaml . | nindent 8 }}

0 commit comments

Comments
 (0)