Skip to content

Commit 33783b4

Browse files
committed
fix(monitoring): stop a policy selector leaking into other constraints
The helper gave a platform constraint the tier's selector through a merge inside ternary, and ternary evaluates both branches, so the merge also ran for a constraint that brings a selector of its own. merge writes into its first argument and recurses into the maps both sides hold. The first argument held the shared $selector map, so the labels or matchExpressions of that own selector were written into $selector itself. Every constraint without a selector holds that same map and the list is rendered once at the end, so all of them came out with the foreign terms added, before or after the constraint that brought them. Such a constraint selected only those of the tier's pods that also match the other selector, and on pods without those labels it spread nothing. Only a policy that mixes constraints with and without a selector is affected. The default and other policies render as before. The merge now goes into a deep copy of the constraint, the order the keycloak chart uses for its database constraints, so $selector is never written. Two new cases pin a constraint without a selector after and before one with its own, the first with matchLabels and the second with matchExpressions. Assisted-by: LLM Signed-off-by: Yan Bondarenko <[email protected]>
1 parent 0dbbb3b commit 33783b4

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{{- end -}}
1414
{{- $constraints := list -}}
1515
{{- range $global -}}
16-
{{- $constraints = append $constraints (ternary . (merge (dict "labelSelector" $selector) .) (hasKey . "labelSelector")) -}}
16+
{{- $constraints = append $constraints (ternary . (merge (deepCopy .) (dict "labelSelector" $selector)) (hasKey . "labelSelector")) -}}
1717
{{- end -}}
1818
{{- if not $constraints -}}
1919
{{- $default := dict "maxSkew" 1 "topologyKey" "kubernetes.io/hostname" "whenUnsatisfiable" (index . 3) "labelSelector" $selector -}}

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,79 @@ tests:
375375
labelSelector:
376376
matchLabels:
377377
example.org/spread: all
378+
379+
- it: gives the component's selector to a constraint after one that sets its own
380+
template: templates/vm/vmcluster.yaml
381+
set:
382+
_cluster:
383+
scheduling:
384+
globalAppTopologySpreadConstraints: |
385+
topologySpreadConstraints:
386+
- maxSkew: 1
387+
topologyKey: topology.kubernetes.io/zone
388+
whenUnsatisfiable: ScheduleAnyway
389+
labelSelector:
390+
matchLabels:
391+
example.org/spread: all
392+
- maxSkew: 1
393+
topologyKey: kubernetes.io/hostname
394+
whenUnsatisfiable: DoNotSchedule
395+
documentSelector:
396+
path: metadata.name
397+
value: shortterm
398+
asserts:
399+
- equal:
400+
path: spec.vmstorage.topologySpreadConstraints
401+
value:
402+
- maxSkew: 1
403+
topologyKey: topology.kubernetes.io/zone
404+
whenUnsatisfiable: ScheduleAnyway
405+
labelSelector:
406+
matchLabels:
407+
example.org/spread: all
408+
- maxSkew: 1
409+
topologyKey: kubernetes.io/hostname
410+
whenUnsatisfiable: DoNotSchedule
411+
labelSelector:
412+
matchLabels:
413+
app.kubernetes.io/name: vmstorage
414+
app.kubernetes.io/instance: shortterm
415+
416+
- it: gives the component's selector to a constraint before one that sets its own
417+
template: templates/vm/vmcluster.yaml
418+
set:
419+
_cluster:
420+
scheduling:
421+
globalAppTopologySpreadConstraints: |
422+
topologySpreadConstraints:
423+
- maxSkew: 1
424+
topologyKey: kubernetes.io/hostname
425+
whenUnsatisfiable: DoNotSchedule
426+
- maxSkew: 1
427+
topologyKey: topology.kubernetes.io/zone
428+
whenUnsatisfiable: ScheduleAnyway
429+
labelSelector:
430+
matchExpressions:
431+
- key: example.org/spread
432+
operator: Exists
433+
documentSelector:
434+
path: metadata.name
435+
value: shortterm
436+
asserts:
437+
- equal:
438+
path: spec.vmstorage.topologySpreadConstraints
439+
value:
440+
- maxSkew: 1
441+
topologyKey: kubernetes.io/hostname
442+
whenUnsatisfiable: DoNotSchedule
443+
labelSelector:
444+
matchLabels:
445+
app.kubernetes.io/name: vmstorage
446+
app.kubernetes.io/instance: shortterm
447+
- maxSkew: 1
448+
topologyKey: topology.kubernetes.io/zone
449+
whenUnsatisfiable: ScheduleAnyway
450+
labelSelector:
451+
matchExpressions:
452+
- key: example.org/spread
453+
operator: Exists

0 commit comments

Comments
 (0)