diff --git a/library/common-test/tests/pod/topologySpreadConstraints.yaml b/library/common-test/tests/pod/topologySpreadConstraints.yaml index 297a97c2..60e16b39 100644 --- a/library/common-test/tests/pod/topologySpreadConstraints.yaml +++ b/library/common-test/tests/pod/topologySpreadConstraints.yaml @@ -5,10 +5,8 @@ release: name: test-release-name namespace: test-release-namespace tests: - - it: should pass with empty topologySpreadConstraints + - it: should pass with missing topologySpreadConstraints on DaemonSet set: - podOptions: - topologySpreadConstraints: [] workload: workload-name1: enabled: true @@ -23,10 +21,26 @@ tests: isNull: path: spec.template.spec.topologySpreadConstraints - - it: should pass defaults with empty topologySpreadConstraints on Deployment + - it: should pass with defaultSpread disabled set: podOptions: - topologySpreadConstraints: [] + defaultSpread: false + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentSetDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentSetDoc + isNull: + path: spec.template.spec.topologySpreadConstraints + + - it: should pass defaults with missing topologySpreadConstraints on Deployment + set: workload: workload-name1: enabled: true @@ -112,8 +126,7 @@ tests: topologyKey: truecharts.org/test whenUnsatisfiable: ScheduleAnyway - - - it: should pass with topologySpreadConstraints from "pod" + - it: should pass with multiple topologySpreadConstraints from "pod" set: podOptions: topologySpreadConstraints: @@ -138,6 +151,13 @@ tests: matchLabels: {} nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor + - maxSkew: 1 + whenUnsatisfiable: ScheduleAnyway + topologyKey: "truecharts.org/test3" + labelSelector: + matchLabels: {} + nodeAffinityPolicy: Honor + nodeTaintsPolicy: Honor asserts: - documentIndex: *deploymentDoc equal: @@ -170,3 +190,10 @@ tests: nodeTaintsPolicy: Honor topologyKey: truecharts.org/test2 whenUnsatisfiable: ScheduleAnyway + - labelSelector: + matchLabels: {} + maxSkew: 1 + nodeAffinityPolicy: Honor + nodeTaintsPolicy: Honor + topologyKey: truecharts.org/test3 + whenUnsatisfiable: ScheduleAnyway diff --git a/library/common/templates/class/_service.tpl b/library/common/templates/class/_service.tpl index e1fd3d4b..bd03ec37 100644 --- a/library/common/templates/class/_service.tpl +++ b/library/common/templates/class/_service.tpl @@ -95,9 +95,9 @@ spec: {{- if not (mustHas $objectData.type $specialTypes) }} selector: {{- if $objectData.selectorLabels }} - {{- tpl ( toYaml $objectData.selectorLabels) $rootCtx | nindent 4 }} + {{- tpl (toYaml $objectData.selectorLabels) $rootCtx | nindent 4 }} {{- else }} - {{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $podValues.shortName) | trim | nindent 4 -}} + {{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $podValues.shortName) | trim | nindent 4 -}} {{- end }} {{- end -}} {{- if eq $objectData.type "ExternalIP" -}} diff --git a/library/common/templates/lib/pod/_topologySpreadConstraints .tpl b/library/common/templates/lib/pod/_topologySpreadConstraints .tpl index 5f24d708..49c2f202 100644 --- a/library/common/templates/lib/pod/_topologySpreadConstraints .tpl +++ b/library/common/templates/lib/pod/_topologySpreadConstraints .tpl @@ -20,7 +20,8 @@ objectData: The object data to be used to render the Pod. {{- $constraints = . -}} {{- end -}} - {{- if and ( or ( eq $objectData.type "Deployment" ) ( eq $objectData.type "StatefulSet" )) $rootCtx.Values.podOptions.defaultSpread -}} + {{- $validTypes := (list "Deployment" "StatefulSet") -}} + {{- if and (mustHas $objectData.type $validTypes) $rootCtx.Values.podOptions.defaultSpread }} - maxSkew: 1 whenUnsatisfiable: ScheduleAnyway topologyKey: "truecharts.org/rack" @@ -38,7 +39,7 @@ objectData: The object data to be used to render the Pod. nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor {{- end -}} - {{ with $constraints }} -{{ . | toYaml | indent 0 }} - {{ end }} + {{- with $constraints -}} {{/* TODO: Template this, so we can add some validation around easy to make mistakes. Low Prio */}} + {{- . | toYaml | nindent 0 }} + {{- end -}} {{- end -}}