From eb43997f9afbf3427a6db48a00eff87be02331ad Mon Sep 17 00:00:00 2001 From: Patrick Vickery Date: Tue, 10 Dec 2024 10:38:52 -0500 Subject: [PATCH] Include labelSelector for affinity and topologySpreadConstraints --- charts/external-dns/CHANGELOG.md | 4 ++ charts/external-dns/ci/ci-values.yaml | 32 ++++++++++ charts/external-dns/templates/_helpers.tpl | 9 +++ charts/external-dns/templates/deployment.yaml | 59 ++++++++++++++++++- 4 files changed, 102 insertions(+), 2 deletions(-) diff --git a/charts/external-dns/CHANGELOG.md b/charts/external-dns/CHANGELOG.md index b8074e57a0..3569fa6869 100644 --- a/charts/external-dns/CHANGELOG.md +++ b/charts/external-dns/CHANGELOG.md @@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ability to configure `imagePullSecrets` via helm `global` value ([#4667](https://github.com/kubernetes-sigs/external-dns/pull/4667)) _@jkroepke_ - Added options to configure `labelFilter` and `managedRecordTypes` via dedicated helm values ([#4849](https://github.com/kubernetes-sigs/external-dns/pull/4849)) _@abaguas_ +### Fixed + +- Fixed automatic addition of pod selector labels to `affinity` and `topologySpreadConstraints` if not defined. _@pvickery-ParamountCommerce_ + ## [v1.15.0] - 2023-09-10 ### Changed diff --git a/charts/external-dns/ci/ci-values.yaml b/charts/external-dns/ci/ci-values.yaml index 97a6626419..200b596409 100644 --- a/charts/external-dns/ci/ci-values.yaml +++ b/charts/external-dns/ci/ci-values.yaml @@ -2,3 +2,35 @@ labelFilter: foo=bar managedRecordTypes: [] provider: name: inmemory +affinity: + podAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + topologyKey: "kubernetes.io/hostname" + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - test + requiredDuringSchedulingIgnoredDuringExecution: + - topologyKey: "kubernetes.io/hostname" + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + topologyKey: "kubernetes.io/hostname" + requiredDuringSchedulingIgnoredDuringExecution: + - topologyKey: "kubernetes.io/hostname" + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - test + +topologySpreadConstraints: + - maxSkew: 1 + topologyKey: "topology.kubernetes.io/zone" + whenUnsatisfiable: "ScheduleAnyway" diff --git a/charts/external-dns/templates/_helpers.tpl b/charts/external-dns/templates/_helpers.tpl index 3ce55cd8a3..13805c7db7 100644 --- a/charts/external-dns/templates/_helpers.tpl +++ b/charts/external-dns/templates/_helpers.tpl @@ -93,3 +93,12 @@ The image to use for optional webhook sidecar {{- printf "%s:%s" .repository .tag }} {{- end }} {{- end }} + +{{/* +The pod affinity default label Selector +*/}} +{{- define "external-dns.labelSelector" -}} +labelSelector: + matchLabels: +{{ include "external-dns.selectorLabels" . | indent 4 }} +{{- end }} diff --git a/charts/external-dns/templates/deployment.yaml b/charts/external-dns/templates/deployment.yaml index 89028b8a03..d15a2881f8 100644 --- a/charts/external-dns/templates/deployment.yaml +++ b/charts/external-dns/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- $defaultSelector := (include "external-dns.labelSelector" $ ) | fromYaml -}} {{- $providerName := tpl (include "external-dns.providerName" .) $ }} apiVersion: apps/v1 kind: Deployment @@ -203,11 +204,65 @@ spec: {{- end }} {{- with .Values.affinity }} affinity: - {{- toYaml . | nindent 8 }} + {{- with .podAffinity }} + podAffinity: + {{- with .preferredDuringSchedulingIgnoredDuringExecution }} + preferredDuringSchedulingIgnoredDuringExecution: + {{- range . }} + podAffinityTerm: + {{- if dig "podAffinityTerm" "labelSelector" nil . }} + {{- toYaml .podAffinityTerm | nindent 14 }} + {{- else }} + {{- (merge $defaultSelector .podAffinityTerm) | toYaml | nindent 14 }} + {{- end }} + {{- end }} + {{- end }} + {{- with .requiredDuringSchedulingIgnoredDuringExecution }} + requiredDuringSchedulingIgnoredDuringExecution: + {{- range . }} + {{- if dig "labelSelector" nil . }} + {{- toYaml . | nindent 12 }} + {{- else }} + {{- (merge $defaultSelector .) | toYaml | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- with .podAntiAffinity }} + podAntiAffinity: + {{- with .preferredDuringSchedulingIgnoredDuringExecution }} + preferredDuringSchedulingIgnoredDuringExecution: + {{- range . }} + podAffinityTerm: + {{- if dig "podAffinityTerm" "labelSelector" nil . }} + {{- toYaml .podAffinityTerm | nindent 14 }} + {{- else }} + {{- (merge $defaultSelector .podAffinityTerm) | toYaml | nindent 14 }} + {{- end }} + {{- end }} + {{- end }} + {{- with .requiredDuringSchedulingIgnoredDuringExecution }} + requiredDuringSchedulingIgnoredDuringExecution: + {{- range . }} + {{- if dig "labelSelector" nil . }} + {{- toYaml . | nindent 12 }} + {{- else }} + {{- (merge $defaultSelector .) | toYaml | nindent 12 }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} {{- end }} {{- with .Values.topologySpreadConstraints }} topologySpreadConstraints: - {{- toYaml . | nindent 8 }} + {{- range . }} + - {{ toYaml . | nindent 10 | trim }} + {{- if not (hasKey . "labelSelector") }} + labelSelector: + matchLabels: + {{- include "external-dns.selectorLabels" $ | nindent 12 }} + {{- end }} + {{- end }} {{- end }} {{- with .Values.tolerations }} tolerations: