From 0dbbb3b157c2e5f3037dccb53b87deba250bc943 Mon Sep 17 00:00:00 2001 From: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Date: Tue, 20 Oct 2026 13:38:25 +0300 Subject: [PATCH] fix(monitoring): fail the render on a malformed platform spread policy A globalAppTopologySpreadConstraints value that did not parse, or that held no topologySpreadConstraints list, gave every tier the chart default without any sign, so the platform's policy was silently not applied. The render now fails and names the parse error, as the chart already does for an empty logsStorages. The tests also pin that a selector the policy sets itself is kept as written. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> --- .../monitoring/templates/_scheduling.tpl | 6 +- .../topology_spread_invalid_policy_test.yaml | 59 +++++++++++++++++++ .../tests/topology_spread_test.yaml | 27 +++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 packages/system/monitoring/tests/topology_spread_invalid_policy_test.yaml diff --git a/packages/system/monitoring/templates/_scheduling.tpl b/packages/system/monitoring/templates/_scheduling.tpl index 6540d4d84..25ff369ad 100644 --- a/packages/system/monitoring/templates/_scheduling.tpl +++ b/packages/system/monitoring/templates/_scheduling.tpl @@ -4,7 +4,11 @@ {{- $global := list -}} {{- with ($root.Values._cluster | default dict).scheduling -}} {{- with get . "globalAppTopologySpreadConstraints" -}} -{{- $global = dig "topologySpreadConstraints" (list) (fromYaml .) -}} +{{- $parsed := fromYaml . -}} +{{- $global = dig "topologySpreadConstraints" (list) $parsed -}} +{{- if or (not (kindIs "slice" $global)) (not $global) -}} +{{- fail (trim (printf "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list. %s" (get $parsed "Error"))) -}} +{{- end -}} {{- end -}} {{- end -}} {{- $constraints := list -}} diff --git a/packages/system/monitoring/tests/topology_spread_invalid_policy_test.yaml b/packages/system/monitoring/tests/topology_spread_invalid_policy_test.yaml new file mode 100644 index 000000000..6558f6764 --- /dev/null +++ b/packages/system/monitoring/tests/topology_spread_invalid_policy_test.yaml @@ -0,0 +1,59 @@ +suite: monitoring refuses a malformed platform spread policy +templates: + - templates/vm/vmcluster.yaml + +release: + name: monitoring-system + namespace: tenant-root + +tests: + - it: fails on a platform policy that does not parse + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + asserts: + - failedTemplate: + errorPattern: "globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list\\. error converting YAML to JSON" + + - it: fails on a platform policy without a topologySpreadConstraints list + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + asserts: + - failedTemplate: + errorPattern: "globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list" + + - it: fails on a platform policy with an empty topologySpreadConstraints list + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + topologySpreadConstraints: [] + asserts: + - failedTemplate: + errorMessage: "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list." + + - it: fails on a platform policy whose topologySpreadConstraints is not a list + template: templates/vm/vmcluster.yaml + set: + _cluster: + scheduling: + globalAppTopologySpreadConstraints: | + topologySpreadConstraints: + maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + asserts: + - failedTemplate: + errorMessage: "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list." diff --git a/packages/system/monitoring/tests/topology_spread_test.yaml b/packages/system/monitoring/tests/topology_spread_test.yaml index dc8273fad..4ede253ea 100644 --- a/packages/system/monitoring/tests/topology_spread_test.yaml +++ b/packages/system/monitoring/tests/topology_spread_test.yaml @@ -348,3 +348,30 @@ tests: matchLabels: app.kubernetes.io/name: vmstorage app.kubernetes.io/instance: shortterm + + - it: keeps a selector the platform policy sets itself + 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 + 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