Skip to content

Commit b9ceff9

Browse files
committed
fix(helm): allow cron pods through app NetworkPolicy
Cursor flagged that when networkPolicy.enabled=true and cronjobs.enabled=true (the recommended production config), the app NetworkPolicy only allowed ingress from realtime and the ingress controller — silently blocking every cron pod's HTTP call to /api/schedules/execute, webhook polls, etc. All 13 default cronjobs would fail. Tag cron pods with a stable simstudio.ai/component-group: cronjob label so the app NetworkPolicy can allow them with a single rule (no per-job enumeration). Rule is conditional on cronjobs.enabled. Adds positive and negative regression tests.
1 parent a4837de commit b9ceff9

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

helm/sim/templates/cronjobs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
labels:
3030
{{- include "sim.selectorLabels" $ | nindent 12 }}
3131
app.kubernetes.io/component: cronjob-{{ $jobConfig.name }}
32+
# Stable group label so NetworkPolicy can allow all cron pods → app
33+
# without enumerating each job's component value.
34+
simstudio.ai/component-group: cronjob
3235
spec:
3336
serviceAccountName: {{ include "sim.serviceAccountName" $ }}
3437
automountServiceAccountToken: false

helm/sim/templates/networkpolicy.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ spec:
2626
- protocol: TCP
2727
port: {{ .Values.app.service.targetPort }}
2828
{{- end }}
29+
# Allow ingress from cron pods (every cron job curls /api/schedules/execute,
30+
# webhook polls, etc. against the app service)
31+
{{- if .Values.cronjobs.enabled }}
32+
- from:
33+
- podSelector:
34+
matchLabels:
35+
{{- include "sim.selectorLabels" . | nindent 10 }}
36+
simstudio.ai/component-group: cronjob
37+
ports:
38+
- protocol: TCP
39+
port: {{ .Values.app.service.targetPort }}
40+
{{- end }}
2941
# Allow ingress from ingress controller (configurable peers; defaults to any)
3042
{{- if .Values.ingress.enabled }}
3143
- from:

helm/sim/tests/networkpolicy_test.yaml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tests:
2929
documentIndex: 0
3030
asserts:
3131
- equal:
32-
path: spec.ingress[1].from
32+
path: spec.ingress[2].from
3333
value:
3434
- {}
3535

@@ -43,7 +43,7 @@ tests:
4343
documentIndex: 0
4444
asserts:
4545
- equal:
46-
path: spec.ingress[1].from
46+
path: spec.ingress[2].from
4747
value:
4848
- namespaceSelector:
4949
matchLabels:
@@ -91,6 +91,43 @@ tests:
9191
- protocol: TCP
9292
port: 4318
9393

94+
- it: app NetworkPolicy allows ingress from cron pods when cronjobs.enabled=true
95+
set:
96+
<<: *defaults
97+
documentIndex: 0
98+
asserts:
99+
- contains:
100+
path: spec.ingress
101+
content:
102+
from:
103+
- podSelector:
104+
matchLabels:
105+
app.kubernetes.io/name: sim
106+
app.kubernetes.io/instance: t
107+
simstudio.ai/component-group: cronjob
108+
ports:
109+
- protocol: TCP
110+
port: 3000
111+
112+
- it: cron→app ingress rule is omitted when cronjobs.enabled=false
113+
set:
114+
<<: *defaults
115+
cronjobs.enabled: false
116+
documentIndex: 0
117+
asserts:
118+
- notContains:
119+
path: spec.ingress
120+
content:
121+
from:
122+
- podSelector:
123+
matchLabels:
124+
app.kubernetes.io/name: sim
125+
app.kubernetes.io/instance: t
126+
simstudio.ai/component-group: cronjob
127+
ports:
128+
- protocol: TCP
129+
port: 3000
130+
94131
- it: egress.extraRules are appended to both app and realtime NetworkPolicies
95132
set:
96133
<<: *defaults

0 commit comments

Comments
 (0)