diff --git a/charts/library/common-test/Chart.yaml b/charts/library/common-test/Chart.yaml index 181e6bb405f..a01d9f9715f 100644 --- a/charts/library/common-test/Chart.yaml +++ b/charts/library/common-test/Chart.yaml @@ -7,7 +7,7 @@ apiVersion: v2 appVersion: unknown dependencies: - name: common - version: ~26.3.0 + version: ~26.4.0 repository: file://../common/ condition: "" alias: "" diff --git a/charts/library/common-test/tests/pod/topologySpreadConstraints.yaml b/charts/library/common-test/tests/pod/topologySpreadConstraints.yaml index ecee7a5815c..3b5f930fe72 100644 --- a/charts/library/common-test/tests/pod/topologySpreadConstraints.yaml +++ b/charts/library/common-test/tests/pod/topologySpreadConstraints.yaml @@ -120,6 +120,40 @@ tests: topologyKey: truecharts.org/test whenUnsatisfiable: ScheduleAnyway + - it: should pass with topologyKey from "global" + set: + global: + fallbackDefaults: + topologyKey: "truecharts.org/test" + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: test-release-name + app.kubernetes.io/name: common-test + pod.name: workload-name1 + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.topologySpreadConstraints + value: + - labelSelector: + matchLabels: + app.kubernetes.io/instance: test-release-name + app.kubernetes.io/name: common-test + pod.name: workload-name1 + maxSkew: 1 + nodeAffinityPolicy: Honor + nodeTaintsPolicy: Honor + topologyKey: truecharts.org/test + whenUnsatisfiable: ScheduleAnyway + - it: should pass with multiple topologySpreadConstraints from "pod" set: podOptions: diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 3e0457d2f52..e00cfe954f7 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 26.3.0 +version: 26.4.0 diff --git a/charts/library/common/templates/lib/pod/_topologySpreadConstraints .tpl b/charts/library/common/templates/lib/pod/_topologySpreadConstraints .tpl index 59ddf988420..66c018fa12e 100644 --- a/charts/library/common/templates/lib/pod/_topologySpreadConstraints .tpl +++ b/charts/library/common/templates/lib/pod/_topologySpreadConstraints .tpl @@ -24,7 +24,7 @@ objectData: The object data to be used to render the Pod. {{- if and (mustHas $objectData.type $validTypes) $rootCtx.Values.podOptions.defaultSpread }} - maxSkew: 1 whenUnsatisfiable: ScheduleAnyway - topologyKey: "kubernetes.io/hostname" + topologyKey: {{ default "kubernetes.io/hostname" $rootCtx.Values.global.fallbackDefaults.topologyKey }} labelSelector: matchLabels: {{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | indent 6 }} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index a2b3af98b93..4630135b524 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -57,6 +57,9 @@ global: # will be used for all CNPG objects # Can be overruled per CNPG objects pgVersion: 16 + # -- Define a topologyKey for default topologySpreadConstraints + # Will be used when defaultSpread: true + topologyKey: kubernetes.io/hostname metallb: # -- Adds metalLB annotations to services addServiceAnnotations: true diff --git a/website/src/content/docs/common/fallbackDefaults.md b/website/src/content/docs/common/fallbackDefaults.md index 236a89815ca..923d52e50f5 100644 --- a/website/src/content/docs/common/fallbackDefaults.md +++ b/website/src/content/docs/common/fallbackDefaults.md @@ -48,6 +48,7 @@ fallbackDefaults: timeoutSeconds: 2 failureThreshold: 60 successThreshold: 1 + topologyKey: kubernetes.io/hostname ``` ## `probeType` @@ -779,6 +780,22 @@ fallbackDefaults: successThreshold: 1 ``` +--- + +## `topologyKey` + +Define default topologyKey for topologySpreadConstraints in podOptions + + +| | | +| ---------- | ------------------------------ | +| Key | `fallbackDefaults.topologyKey` | +| Type | `string` | +| Required | ❌ | +| Helm `tpl` | ❌ | +| Default | `kubernetes.io/hostname` | + + --- ## Full Examples @@ -808,4 +825,5 @@ fallbackDefaults: timeoutSeconds: 2 failureThreshold: 60 successThreshold: 1 + topologyKey: truecharts.org/example ```