diff --git a/packages/system/monitoring/templates/_scheduling.tpl b/packages/system/monitoring/templates/_scheduling.tpl index 25ff369ad..e7358c5c6 100644 --- a/packages/system/monitoring/templates/_scheduling.tpl +++ b/packages/system/monitoring/templates/_scheduling.tpl @@ -13,7 +13,7 @@ {{- end -}} {{- $constraints := list -}} {{- range $global -}} -{{- $constraints = append $constraints (ternary . (merge (dict "labelSelector" $selector) .) (hasKey . "labelSelector")) -}} +{{- $constraints = append $constraints (ternary . (merge (deepCopy .) (dict "labelSelector" $selector)) (hasKey . "labelSelector")) -}} {{- end -}} {{- if not $constraints -}} {{- $default := dict "maxSkew" 1 "topologyKey" "kubernetes.io/hostname" "whenUnsatisfiable" (index . 3) "labelSelector" $selector -}} diff --git a/packages/system/monitoring/tests/topology_spread_test.yaml b/packages/system/monitoring/tests/topology_spread_test.yaml index 4ede253ea..14a20da21 100644 --- a/packages/system/monitoring/tests/topology_spread_test.yaml +++ b/packages/system/monitoring/tests/topology_spread_test.yaml @@ -375,3 +375,79 @@ tests: labelSelector: matchLabels: example.org/spread: all + + - it: gives the component's selector to a constraint after one that sets its own + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + example.org/spread: all + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + documentSelector: + path: metadata.name + value: shortterm + asserts: + - equal: + path: spec.vmstorage.topologySpreadConstraints + value: + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + example.org/spread: all + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: vmstorage + app.kubernetes.io/instance: shortterm + + - it: gives the component's selector to a constraint before one that sets its own + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchExpressions: + - key: example.org/spread + operator: Exists + documentSelector: + path: metadata.name + value: shortterm + asserts: + - equal: + path: spec.vmstorage.topologySpreadConstraints + value: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: vmstorage + app.kubernetes.io/instance: shortterm + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchExpressions: + - key: example.org/spread + operator: Exists