Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include labelSelector for affinity and topologySpreadConstraints #4666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charts/external-dns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions charts/external-dns/ci/ci-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 9 additions & 0 deletions charts/external-dns/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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" . | nindent 4 }}
{{- end }}
61 changes: 59 additions & 2 deletions charts/external-dns/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $defaultSelector := (include "external-dns.labelSelector" $ ) | fromYaml -}}
{{- $providerName := tpl (include "external-dns.providerName" .) $ }}
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -203,11 +204,67 @@ 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 16 }}
{{- else }}
{{- (merge $defaultSelector .podAffinityTerm) | toYaml | nindent 16 }}
{{- end }}
weight: {{ .weight }}
{{- end }}
{{- end }}
{{- with .requiredDuringSchedulingIgnoredDuringExecution }}
requiredDuringSchedulingIgnoredDuringExecution:
{{- range . }}
{{- if dig "labelSelector" nil . }}
- {{ toYaml . | indent 16 | trim }}
{{- else }}
- {{ (merge $defaultSelector .) | toYaml | indent 16 | trim }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- with .podAntiAffinity }}
podAntiAffinity:
{{- with .preferredDuringSchedulingIgnoredDuringExecution }}
preferredDuringSchedulingIgnoredDuringExecution:
{{- range . }}
- podAffinityTerm:
{{- if dig "podAffinityTerm" "labelSelector" nil . }}
{{- toYaml .podAffinityTerm | nindent 16 }}
{{- else }}
{{- (merge $defaultSelector .podAffinityTerm) | toYaml | nindent 16 }}
{{- end }}
weight: {{ .weight }}
{{- end }}
{{- end }}
{{- with .requiredDuringSchedulingIgnoredDuringExecution }}
requiredDuringSchedulingIgnoredDuringExecution:
{{- range . }}
{{- if dig "labelSelector" nil . }}
- {{ toYaml . | indent 16 | trim }}
{{- else }}
- {{ (merge $defaultSelector .) | toYaml | indent 16 | trim }}
{{- 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:
Expand Down
Loading