Skip to content

Conversation

@bderrly
Copy link

@bderrly bderrly commented Nov 26, 2024

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.

The alternative to this is to run the configuration in this key through the tpl function to allow users the ability to call named templates. Similar to how extraObjects is handled.

@bderrly bderrly force-pushed the default-topology-constraints branch from 076c5ec to ed379a9 Compare November 26, 2024 23:54
topologySpreadConstraints:
{{- range $_, $entry := . }}
{{- if not (dig "labelSelectors" "matchLabels" false $entry) }}
{{- $ls := "labelSelectors:\n matchLabels: {}" | fromYaml }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very familiar with this, but the \n seems a bit hacky. I wonder if we can do this more cleanly with a dict.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's kind of gross. I just updated this to use the dict function to create the nested dictionary keys.

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bderrly.
cc @jszwedko does this make sense to you?

@jszwedko
Copy link
Member

jszwedko commented Dec 2, 2024

I'm afraid I don't know enough about topologySpreadConstraints to comment 😓

@pront
Copy link
Member

pront commented Feb 5, 2025

Disclaimer: Bear with me as I ramp up in this area.

Would this be considered a breaking change? Per https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/ I think this can change pod grouping.

@bderrly bderrly changed the title Adds default selectorLabels to topologySpreadConstraints if not otherwise specified. Add default selectorLabel to topologySpreadConstraints if not otherwise specified Feb 17, 2025
@bderrly
Copy link
Author

bderrly commented Feb 17, 2025

I think this has the potential to cause a "breaking" change in that it may cause the spread constraint functionality to begin working as intended. That is, if a user has not explicitly defined the selectorLabel field in their values file, then no matching pods will be selected and the spread constraint feature will not function as expected.

I tested this behavior on the HEAD of the develop branch using kind (kubernetes version 1.32) and I received the following warning from kubernetes:

W0217 11:08:54.767705 6459 warnings.go:70] spec.template.spec.topologySpreadConstraints[0].labelSelector: a null labelSelector results in matching no pod

The chart installed successfully and the pod is running. With this PR, however, there was no such warning and, presumably, the spread constraint feature will operate as expected.

@pront pront self-assigned this Feb 18, 2025
bderrly and others added 4 commits May 14, 2025 22:26
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.
@bderrly bderrly force-pushed the default-topology-constraints branch from 0873170 to 7d3908a Compare May 15, 2025 05:26
@bderrly
Copy link
Author

bderrly commented May 15, 2025

@pront, I see you approved this a while back. Is there anything else you want to see before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants