Skip to content

Commit e51d535

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 e51d535

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

templates/deployment-sidekiq.yaml

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

templates/deployment-web.yaml

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

0 commit comments

Comments
 (0)