Skip to content

Commit e2d5c80

Browse files
authored
feat(chart): add supervisor.extraInitContainers hook (PLT-1553) (#27)
feat(chart): add supervisor.extraInitContainers hook (PLT-1553)
2 parents 16ec612 + fbb70e0 commit e2d5c80

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

‎hosting/k8s/helm/Chart.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: trigger
33
description: The official Trigger.dev Helm chart
44
type: application
5-
version: 4.5.7-plt663.9
5+
version: 4.5.7-plt663.10
66
appVersion: v4.5.7
77
home: https://trigger.dev
88
sources:

‎hosting/k8s/helm/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ supervisor:
259259

260260
The supervisor `extraVolumes` / `extraVolumeMounts` keys behave identically to the webapp ones. Both render unconditionally — they don't require any other feature toggle.
261261

262+
### Supervisor init containers
263+
264+
`supervisor.extraInitContainers` prepends init containers to the supervisor pod. It accepts a list, or a string that is `tpl`-rendered in chart scope (the same contract as `webapp.extraContainers`), so entries can use helpers such as `trigger-v4.fullname`.
265+
266+
The supervisor makes one connect call to the webapp when it boots and exits 1 if that call fails; Kubernetes then restarts it with backoff. If your webapp is a single replica that runs migrations at boot, a node drain that reschedules both pods leaves the supervisor crash-looping until the webapp is back. Gating on the webapp health endpoint avoids the restarts:
267+
268+
```yaml
269+
supervisor:
270+
extraInitContainers: |
271+
- name: wait-for-webapp
272+
image: curlimages/curl:8.5.0
273+
command: ["/bin/sh", "-c"]
274+
args:
275+
- |
276+
until curl -sf http://{{ include "trigger-v4.fullname" . }}-webapp:{{ .Values.webapp.service.port }}/healthcheck; do
277+
echo "webapp not ready"; sleep 5
278+
done
279+
```
280+
281+
The pod sits in `Init:0/1` (no restart counter) until the webapp answers, then the supervisor starts and connects normally.
282+
262283
### Worker pod security context
263284

264285
By default the supervisor doesn't set a `securityContext` on the worker pods it schedules — it lets the cluster's PodSecurity admission / SCC apply whatever defaults are configured. If you need to enforce explicit pod- or container-level security, set:

‎hosting/k8s/helm/templates/supervisor.yaml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,23 @@ spec:
7676
{{- with .Values.supervisor.podSecurityContext }}
7777
{{- toYaml . | nindent 8 }}
7878
{{- end }}
79-
{{- if not .Values.webapp.bootstrap.enabled }}
79+
{{- /*
80+
extraInitContainers is tpl-rendered into a variable first (string or
81+
list, same contract as webapp.extraContainers) so `initContainers:` is
82+
only emitted when something actually renders — a template string that
83+
evaluates to nothing would otherwise leave a null list behind.
84+
*/}}
85+
{{- $extraInitContainers := "" }}
86+
{{- with .Values.supervisor.extraInitContainers }}
87+
{{- if kindIs "string" . }}
88+
{{- $extraInitContainers = tpl . $ | trim }}
89+
{{- else }}
90+
{{- $extraInitContainers = tpl (toYaml .) $ | trim }}
91+
{{- end }}
92+
{{- end }}
93+
{{- if or (not .Values.webapp.bootstrap.enabled) $extraInitContainers }}
8094
initContainers:
95+
{{- if not .Values.webapp.bootstrap.enabled }}
8196
- name: init-shared
8297
image: busybox:1.35
8398
command: ['sh', '-c', 'mkdir -p /home/node/shared']
@@ -86,6 +101,10 @@ spec:
86101
volumeMounts:
87102
- name: shared
88103
mountPath: /home/node/shared
104+
{{- end }}
105+
{{- with $extraInitContainers }}
106+
{{- . | nindent 8 }}
107+
{{- end }}
89108
{{- end }}
90109
containers:
91110
- name: supervisor

‎hosting/k8s/helm/values.yaml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,23 @@ supervisor:
419419
# mountPath: /etc/ssl/enterprise-ca
420420
# readOnly: true
421421

422+
# Extra init containers prepended to the Supervisor pod. Accepts a list,
423+
# or a string that is tpl-rendered in chart scope (same contract as
424+
# `webapp.extraContainers`), so entries can reference helpers and values.
425+
#
426+
# Typical use: gate supervisor start on the webapp's /healthcheck. The
427+
# supervisor makes a single connect call to the webapp at boot and exits 1
428+
# when it fails, so a webapp that is still running boot migrations turns
429+
# into a supervisor CrashLoopBackOff. Waiting here keeps the pod in
430+
# Init:0/1 (no restart counter) until the webapp answers.
431+
extraInitContainers:
432+
[]
433+
# - name: wait-for-webapp
434+
# image: curlimages/curl:8.5.0
435+
# command: ["/bin/sh", "-c"]
436+
# args:
437+
# - until curl -sf http://{{ include "trigger-v4.fullname" . }}-webapp:{{ .Values.webapp.service.port }}/healthcheck; do sleep 5; done
438+
422439
# ServiceMonitor for Prometheus monitoring
423440
serviceMonitor:
424441
enabled: false

0 commit comments

Comments
 (0)