Skip to content

Commit a4837de

Browse files
committed
fix(helm): make topologySpreadConstraints per-component to match docstring
Greptile flagged that sim.topologySpreadConstraints helper docstring promised per-component config (.Values.app, .Values.realtime, ...) but call sites passed .Values, so any app.topologySpreadConstraints / realtime.topologySpreadConstraints set by the user was silently dropped. The single global key also prevented distinct app-vs-realtime spread rules. Pass .Values.app / .Values.realtime to the helper at each call site; move the top-level topologySpreadConstraints key into both component sections in values.yaml. Adds a regression test that app constraints don't leak onto the realtime pod.
1 parent 570e5f0 commit a4837de

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

helm/sim/templates/deployment-app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
{{- include "sim.nodeSelector" .Values.app | nindent 6 }}
4141
{{- include "sim.tolerations" .Values | nindent 6 }}
4242
{{- include "sim.affinity" .Values | nindent 6 }}
43-
{{- include "sim.topologySpreadConstraints" .Values | nindent 6 }}
43+
{{- include "sim.topologySpreadConstraints" .Values.app | nindent 6 }}
4444
{{- if .Values.migrations.enabled }}
4545
initContainers:
4646
- name: migrations

helm/sim/templates/deployment-realtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
{{- include "sim.nodeSelector" .Values.realtime | nindent 6 }}
3838
{{- include "sim.tolerations" .Values | nindent 6 }}
3939
{{- include "sim.affinity" .Values | nindent 6 }}
40-
{{- include "sim.topologySpreadConstraints" .Values | nindent 6 }}
40+
{{- include "sim.topologySpreadConstraints" .Values.realtime | nindent 6 }}
4141
containers:
4242
- name: realtime
4343
image: {{ include "sim.image" (dict "imageRoot" .Values.realtime.image "global" .Values.global "chartAppVersion" .Chart.AppVersion) }}

helm/sim/tests/pod-rollout_test.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tests:
4040
template: deployment-app.yaml
4141
set:
4242
<<: *defaults
43-
topologySpreadConstraints:
43+
app.topologySpreadConstraints:
4444
- maxSkew: 1
4545
topologyKey: topology.kubernetes.io/zone
4646
whenUnsatisfiable: ScheduleAnyway
@@ -59,7 +59,7 @@ tests:
5959
template: deployment-realtime.yaml
6060
set:
6161
<<: *defaults
62-
topologySpreadConstraints:
62+
realtime.topologySpreadConstraints:
6363
- maxSkew: 1
6464
topologyKey: topology.kubernetes.io/zone
6565
whenUnsatisfiable: ScheduleAnyway
@@ -70,3 +70,18 @@ tests:
7070
- equal:
7171
path: spec.template.spec.topologySpreadConstraints[0].topologyKey
7272
value: topology.kubernetes.io/zone
73+
74+
- it: app topologySpreadConstraints do not leak onto realtime pod
75+
template: deployment-realtime.yaml
76+
set:
77+
<<: *defaults
78+
app.topologySpreadConstraints:
79+
- maxSkew: 1
80+
topologyKey: topology.kubernetes.io/zone
81+
whenUnsatisfiable: ScheduleAnyway
82+
labelSelector:
83+
matchLabels:
84+
app.kubernetes.io/name: sim
85+
asserts:
86+
- isNull:
87+
path: spec.template.spec.topologySpreadConstraints

helm/sim/values.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ app:
4141
# Node selector for pod scheduling (leave empty to allow scheduling on any node)
4242
nodeSelector: {}
4343

44+
# Topology spread constraints for app pods (HA across zones / nodes).
45+
# Each entry must include its own labelSelector.
46+
topologySpreadConstraints: []
47+
4448
# Pod security context
4549
podSecurityContext:
4650
fsGroup: 1001
@@ -409,11 +413,15 @@ realtime:
409413

410414
# Node selector for pod scheduling (leave empty to allow scheduling on any node)
411415
nodeSelector: {}
412-
416+
417+
# Topology spread constraints for realtime pods (HA across zones / nodes).
418+
# Each entry must include its own labelSelector.
419+
topologySpreadConstraints: []
420+
413421
# Pod security context
414422
podSecurityContext:
415423
fsGroup: 1001
416-
424+
417425
# Container security context
418426
securityContext:
419427
runAsNonRoot: true
@@ -1051,19 +1059,6 @@ affinity: {}
10511059
# Tolerations for scheduling on tainted nodes
10521060
tolerations: []
10531061

1054-
# Topology spread constraints — for HA across zones / nodes.
1055-
# Each entry must include its own labelSelector. Common pattern:
1056-
#
1057-
# topologySpreadConstraints:
1058-
# - maxSkew: 1
1059-
# topologyKey: topology.kubernetes.io/zone
1060-
# whenUnsatisfiable: ScheduleAnyway
1061-
# labelSelector:
1062-
# matchLabels:
1063-
# app.kubernetes.io/name: sim
1064-
# app.kubernetes.io/instance: my-release
1065-
topologySpreadConstraints: []
1066-
10671062
# CronJob configuration for scheduled tasks
10681063
cronjobs:
10691064
# Enable/disable all cron jobs

0 commit comments

Comments
 (0)