Skip to content

Commit 40f5d5c

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]> (cherry picked from commit 33783b4)
1 parent def0688 commit 40f5d5c

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
@@ -306,3 +306,79 @@ tests:
306306
labelSelector:
307307
matchLabels:
308308
example.org/spread: all
309+
310+
- it: gives the component's selector to a constraint after one that sets its own
311+
template: templates/vm/vmcluster.yaml
312+
set:
313+
_cluster:
314+
scheduling:
315+
globalAppTopologySpreadConstraints: |
316+
topologySpreadConstraints:
317+
- maxSkew: 1
318+
topologyKey: topology.kubernetes.io/zone
319+
whenUnsatisfiable: ScheduleAnyway
320+
labelSelector:
321+
matchLabels:
322+
example.org/spread: all
323+
- maxSkew: 1
324+
topologyKey: kubernetes.io/hostname
325+
whenUnsatisfiable: DoNotSchedule
326+
documentSelector:
327+
path: metadata.name
328+
value: shortterm
329+
asserts:
330+
- equal:
331+
path: spec.vmstorage.topologySpreadConstraints
332+
value:
333+
- maxSkew: 1
334+
topologyKey: topology.kubernetes.io/zone
335+
whenUnsatisfiable: ScheduleAnyway
336+
labelSelector:
337+
matchLabels:
338+
example.org/spread: all
339+
- maxSkew: 1
340+
topologyKey: kubernetes.io/hostname
341+
whenUnsatisfiable: DoNotSchedule
342+
labelSelector:
343+
matchLabels:
344+
app.kubernetes.io/name: vmstorage
345+
app.kubernetes.io/instance: shortterm
346+
347+
- it: gives the component's selector to a constraint before one that sets its own
348+
template: templates/vm/vmcluster.yaml
349+
set:
350+
_cluster:
351+
scheduling:
352+
globalAppTopologySpreadConstraints: |
353+
topologySpreadConstraints:
354+
- maxSkew: 1
355+
topologyKey: kubernetes.io/hostname
356+
whenUnsatisfiable: DoNotSchedule
357+
- maxSkew: 1
358+
topologyKey: topology.kubernetes.io/zone
359+
whenUnsatisfiable: ScheduleAnyway
360+
labelSelector:
361+
matchExpressions:
362+
- key: example.org/spread
363+
operator: Exists
364+
documentSelector:
365+
path: metadata.name
366+
value: shortterm
367+
asserts:
368+
- equal:
369+
path: spec.vmstorage.topologySpreadConstraints
370+
value:
371+
- maxSkew: 1
372+
topologyKey: kubernetes.io/hostname
373+
whenUnsatisfiable: DoNotSchedule
374+
labelSelector:
375+
matchLabels:
376+
app.kubernetes.io/name: vmstorage
377+
app.kubernetes.io/instance: shortterm
378+
- maxSkew: 1
379+
topologyKey: topology.kubernetes.io/zone
380+
whenUnsatisfiable: ScheduleAnyway
381+
labelSelector:
382+
matchExpressions:
383+
- key: example.org/spread
384+
operator: Exists

0 commit comments

Comments
 (0)