From 188b46bf29b1fdcf7f625de78185fa5877912edf Mon Sep 17 00:00:00 2001 From: Dmitrii Golubtsov Date: Fri, 25 Apr 2025 14:54:25 +0300 Subject: [PATCH] Add podAntiAffinity rule --- .../mysql-operator/templates/statefulset.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/deploy/charts/mysql-operator/templates/statefulset.yaml b/deploy/charts/mysql-operator/templates/statefulset.yaml index 2ff2e4c05..123c3d828 100644 --- a/deploy/charts/mysql-operator/templates/statefulset.yaml +++ b/deploy/charts/mysql-operator/templates/statefulset.yaml @@ -156,9 +156,19 @@ spec: nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.affinity }} + {{- if gt (int .Values.replicaCount) 1 }} affinity: - {{- toYaml . | nindent 8 }} + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + podAffinityTerm: + labelSelector: + matchLabels: + {{ include "mysql-operator.selectorLabels" . | nindent 20 }} + topologyKey: kubernetes.io/hostname + {{- else if .Values.affinity }} + affinity: + {{- toYaml .Values.affinity | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: