Skip to content

Commit 9a54181

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 9a54181

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

templates/deployment-sidekiq.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ 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 (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity).podAffinity }}
50+
{{- if or (eq "ReadWriteOnce" $context.Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" $context.Values.mastodon.persistence.system.accessMode) }}
51+
podAffinity:
52+
requiredDuringSchedulingIgnoredDuringExecution:
53+
- labelSelector:
54+
matchExpressions:
55+
- key: app.kubernetes.io/part-of
56+
operator: In
57+
values:
58+
- rails
59+
topologyKey: kubernetes.io/hostname
60+
{{- end }}
61+
{{- end }}
62+
{{- with (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) }}
63+
{{- toYaml . | nindent 8 }}
64+
{{- end }}
5265
{{- if (not $context.Values.mastodon.s3.enabled) }}
5366
volumes:
5467
- name: assets

templates/deployment-web.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,23 @@ 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 (default .Values.affinity .Values.mastodon.web.affinity).podAffinity }}
123+
{{- if or (eq "ReadWriteOnce" .Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" .Values.mastodon.persistence.system.accessMode) }}
124+
podAffinity:
125+
requiredDuringSchedulingIgnoredDuringExecution:
126+
- labelSelector:
127+
matchExpressions:
128+
- key: app.kubernetes.io/part-of
129+
operator: In
130+
values:
131+
- rails
132+
topologyKey: kubernetes.io/hostname
133+
{{- end }}
134+
{{- end }}
135+
{{- with (default .Values.affinity .Values.mastodon.web.affinity) }}
136+
{{- toYaml . | nindent 8 }}
137+
{{- end }}
125138
{{- with .Values.tolerations }}
126139
tolerations:
127140
{{- toYaml . | nindent 8 }}

0 commit comments

Comments
 (0)