Skip to content

Commit def0688

Browse files
committed
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 <[email protected]> (cherry picked from commit 0dbbb3b)
1 parent 1dde162 commit def0688

3 files changed

Lines changed: 91 additions & 1 deletion

File tree

‎packages/system/monitoring/templates/_scheduling.tpl‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
{{- $global := list -}}
55
{{- with ($root.Values._cluster | default dict).scheduling -}}
66
{{- with get . "globalAppTopologySpreadConstraints" -}}
7-
{{- $global = dig "topologySpreadConstraints" (list) (fromYaml .) -}}
7+
{{- $parsed := fromYaml . -}}
8+
{{- $global = dig "topologySpreadConstraints" (list) $parsed -}}
9+
{{- if or (not (kindIs "slice" $global)) (not $global) -}}
10+
{{- fail (trim (printf "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list. %s" (get $parsed "Error"))) -}}
11+
{{- end -}}
812
{{- end -}}
913
{{- end -}}
1014
{{- $constraints := list -}}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
suite: monitoring refuses a malformed platform spread policy
2+
templates:
3+
- templates/vm/vmcluster.yaml
4+
5+
release:
6+
name: monitoring-system
7+
namespace: tenant-root
8+
9+
tests:
10+
- it: fails on a platform policy that does not parse
11+
template: templates/vm/vmcluster.yaml
12+
set:
13+
_cluster:
14+
scheduling:
15+
globalAppTopologySpreadConstraints: |
16+
topologySpreadConstraints:
17+
- maxSkew: 1
18+
topologyKey: kubernetes.io/hostname
19+
asserts:
20+
- failedTemplate:
21+
errorPattern: "globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list\\. error converting YAML to JSON"
22+
23+
- it: fails on a platform policy without a topologySpreadConstraints list
24+
template: templates/vm/vmcluster.yaml
25+
set:
26+
_cluster:
27+
scheduling:
28+
globalAppTopologySpreadConstraints: |
29+
- maxSkew: 1
30+
topologyKey: kubernetes.io/hostname
31+
whenUnsatisfiable: ScheduleAnyway
32+
asserts:
33+
- failedTemplate:
34+
errorPattern: "globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list"
35+
36+
- it: fails on a platform policy with an empty topologySpreadConstraints list
37+
template: templates/vm/vmcluster.yaml
38+
set:
39+
_cluster:
40+
scheduling:
41+
globalAppTopologySpreadConstraints: |
42+
topologySpreadConstraints: []
43+
asserts:
44+
- failedTemplate:
45+
errorMessage: "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list."
46+
47+
- it: fails on a platform policy whose topologySpreadConstraints is not a list
48+
template: templates/vm/vmcluster.yaml
49+
set:
50+
_cluster:
51+
scheduling:
52+
globalAppTopologySpreadConstraints: |
53+
topologySpreadConstraints:
54+
maxSkew: 1
55+
topologyKey: kubernetes.io/hostname
56+
whenUnsatisfiable: ScheduleAnyway
57+
asserts:
58+
- failedTemplate:
59+
errorMessage: "monitoring: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list."

‎packages/system/monitoring/tests/topology_spread_test.yaml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,30 @@ tests:
279279
matchLabels:
280280
app.kubernetes.io/name: vmstorage
281281
app.kubernetes.io/instance: shortterm
282+
283+
- it: keeps a selector the platform policy sets itself
284+
template: templates/vm/vmcluster.yaml
285+
set:
286+
_cluster:
287+
scheduling:
288+
globalAppTopologySpreadConstraints: |
289+
topologySpreadConstraints:
290+
- maxSkew: 1
291+
topologyKey: topology.kubernetes.io/zone
292+
whenUnsatisfiable: ScheduleAnyway
293+
labelSelector:
294+
matchLabels:
295+
example.org/spread: all
296+
documentSelector:
297+
path: metadata.name
298+
value: shortterm
299+
asserts:
300+
- equal:
301+
path: spec.vmstorage.topologySpreadConstraints
302+
value:
303+
- maxSkew: 1
304+
topologyKey: topology.kubernetes.io/zone
305+
whenUnsatisfiable: ScheduleAnyway
306+
labelSelector:
307+
matchLabels:
308+
example.org/spread: all

0 commit comments

Comments
 (0)