From 5b78e29640ee0d42e184b8fb31557a587727998e Mon Sep 17 00:00:00 2001 From: Brian Derr Date: Tue, 26 Nov 2024 15:29:39 -0800 Subject: [PATCH 1/3] Adds default selectorLabels if not otherwise specified. If someone defines one or more entries in the `topologySpreadConstraints` list and does not define the `labelSelectors.matchLabels` keys then default values will be added. Most people are likely going to want the default selectorLabels so the spread constraints match what they are deploying with this chart. --- charts/vector/templates/_pod.tpl | 7 +++++++ charts/vector/values.yaml | 2 ++ 2 files changed, 9 insertions(+) diff --git a/charts/vector/templates/_pod.tpl b/charts/vector/templates/_pod.tpl index 2090e7f..82bc0a6 100644 --- a/charts/vector/templates/_pod.tpl +++ b/charts/vector/templates/_pod.tpl @@ -174,6 +174,13 @@ tolerations: {{- end }} {{- with .Values.topologySpreadConstraints }} topologySpreadConstraints: +{{- range $_, $entry := . }} +{{- if not (dig "labelSelectors" "matchLabels" false $entry) }} + {{- $ls := "labelSelectors:\n matchLabels: {}" | fromYaml }} + {{- $_ := set $ls.labelSelectors "matchLabels" (include "vector.selectorLabels" $ | fromYaml) }} + {{- $entry := merge $entry $ls }} +{{- end }} +{{- end }} {{- toYaml . | nindent 2 }} {{- end }} volumes: diff --git a/charts/vector/values.yaml b/charts/vector/values.yaml index 2deeb3e..8271246 100644 --- a/charts/vector/values.yaml +++ b/charts/vector/values.yaml @@ -232,6 +232,8 @@ affinity: {} # topologySpreadConstraints -- Configure [topology spread constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/) # for Vector Pods. Valid for the "Aggregator" and "Stateless-Aggregator" roles. +# +# If there are no "selectorLabels.matchLabels" are defined then defaults will be used to match the selectorLabels of this instance. topologySpreadConstraints: [] # Configuration for Vector's Service. From ed379a902925715bcdd20976073a06923482a2f2 Mon Sep 17 00:00:00 2001 From: Brian Derr Date: Tue, 26 Nov 2024 15:49:29 -0800 Subject: [PATCH 2/3] Edit poor wording in values.yaml file. --- charts/vector/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/vector/values.yaml b/charts/vector/values.yaml index 8271246..9ceded2 100644 --- a/charts/vector/values.yaml +++ b/charts/vector/values.yaml @@ -233,7 +233,7 @@ affinity: {} # topologySpreadConstraints -- Configure [topology spread constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/) # for Vector Pods. Valid for the "Aggregator" and "Stateless-Aggregator" roles. # -# If there are no "selectorLabels.matchLabels" are defined then defaults will be used to match the selectorLabels of this instance. +# If no "selectorLabels.matchLabels" are defined then defaults will be used to match the selectorLabels of this instance. topologySpreadConstraints: [] # Configuration for Vector's Service. From abca46d4e434996b8758a58bb0f31917744020de Mon Sep 17 00:00:00 2001 From: Brian Derr Date: Mon, 2 Dec 2024 10:22:20 -0800 Subject: [PATCH 3/3] Create dictionary with 'dict' function rather than 'fromYaml'. --- charts/vector/templates/_pod.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/charts/vector/templates/_pod.tpl b/charts/vector/templates/_pod.tpl index 82bc0a6..c215af0 100644 --- a/charts/vector/templates/_pod.tpl +++ b/charts/vector/templates/_pod.tpl @@ -176,7 +176,8 @@ tolerations: topologySpreadConstraints: {{- range $_, $entry := . }} {{- if not (dig "labelSelectors" "matchLabels" false $entry) }} - {{- $ls := "labelSelectors:\n matchLabels: {}" | fromYaml }} + {{- $ls := dict -}} + {{- $_ := set $ls "labelSelectors" dict -}} {{- $_ := set $ls.labelSelectors "matchLabels" (include "vector.selectorLabels" $ | fromYaml) }} {{- $entry := merge $entry $ls }} {{- end }}