From de2ba75a9ae71c2e16f5da81c5679956a6dc5436 Mon Sep 17 00:00:00 2001 From: Julien Francoz Date: Tue, 18 Mar 2025 11:03:54 +0100 Subject: [PATCH] render template in topologySpreadConstraint This allow to reuse all labels from Pods The `if kindIs "slice"` keeps compatiblity with previous topologySpreadConstraints --- chart/templates/deployment.yaml | 4 ++++ chart/templates/statefulset.yaml | 4 ++++ chart/values.yaml | 25 ++++++++++++------------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 8518cceb..1825d36f 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -38,7 +38,11 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} {{- with .Values.topologySpreadConstraints }} topologySpreadConstraints: + {{- if kindIs "slice" . }} {{- toYaml . | nindent 8 }} + {{- else }} + {{- tpl . $ | nindent 8 }} + {{- end }} {{- end }} {{- if .Values.initContainers }} initContainers: diff --git a/chart/templates/statefulset.yaml b/chart/templates/statefulset.yaml index d62c5f7e..e9583a1e 100644 --- a/chart/templates/statefulset.yaml +++ b/chart/templates/statefulset.yaml @@ -39,7 +39,11 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} {{- with .Values.topologySpreadConstraints }} topologySpreadConstraints: + {{- if kindIs "slice" . }} {{- toYaml . | nindent 8 }} + {{- else }} + {{- tpl . $ | nindent 8 }} + {{- end }} {{- end }} {{- if .Values.initContainers }} initContainers: diff --git a/chart/values.yaml b/chart/values.yaml index 688554bf..fd1e0ef8 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -104,19 +104,18 @@ lifecycle: {} # - -c # - touch /etc/varnish/fail_probes; sleep 25 -topologySpreadConstraints: {} - # - topologyKey: topology.kubernetes.io/zone - # maxSkew: 1 - # whenUnsatisfiable: ScheduleAnyway - # labelSelector: - # matchLabels: - # app.kubernetes.io/name: kube-httpcache - # - topologyKey: kubernetes.io/hostname - # maxSkew: 1 - # whenUnsatisfiable: ScheduleAnyway - # labelSelector: - # matchLabels: - # app.kubernetes.io/name: kube-httpcache +# topologySpreadConstraints (this value is evaluated as a template) +topologySpreadConstraints: | + - topologyKey: topology.kubernetes.io/zone + maxSkew: 1 + whenUnsatisfiable: ScheduleAnyway + labelSelector: + {{- include "kube-httpcache.selectorLabels" . | nindent 4 }} + - topologyKey: kubernetes.io/hostname + maxSkew: 1 + whenUnsatisfiable: ScheduleAnyway + labelSelector: + {{- include "kube-httpcache.selectorLabels" . | nindent 4 }} initContainers: {} # initContainers: |