Skip to content

Commit 30a2e8c

Browse files
fergusfinnFergusclaude
authored
feat: generic hooks for command, args, init containers and extra objects (#114)
Adds the usual passthroughs so a deployment can extend the dwctl pods without changing the chart: - `command` / `args`: the dwctl container's command and args on the API and Fusillade pods (e.g. to start it through a launcher). - `initContainers`: extra init containers on the API and Fusillade pods; native sidecars (restartPolicy: Always) work too. - `migrations.job.command` / `migrations.job.initContainers`: the same for the migration Job, which keeps `args: [migrate]`. - `extraObjects`: extra manifests rendered as-is, not passed through `tpl`, so their contents are left untouched. Mirrors the existing volumes/volumeMounts layering (top level for the API and Fusillade pods, migrations.job.* for the Job). With none set, the rendered output is byte-identical to before. Claude-Session: https://claude.ai/code/session_01VDPqeJAnWo3dXLuSGDoRDo Co-authored-by: Fergus <fergus.finn@doubleword.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d4a0075 commit 30a2e8c

7 files changed

Lines changed: 202 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ The chart supports both internal and external PostgreSQL databases:
124124
| `config` | Control layer application configuration (YAML) | See values.yaml |
125125
| `env` | Additional environment variables | `{}` |
126126

127+
### Extending the pods
128+
129+
Generic hooks for adding to the dwctl pods without changing the chart.
130+
131+
| Parameter | Description | Default |
132+
|-----------|-------------|---------|
133+
| `command` | Override the dwctl container's command (the image entrypoint is `./dwctl`) on the API and Fusillade pods | `[]` |
134+
| `args` | Override the dwctl container's args on the API and Fusillade pods | `[]` |
135+
| `initContainers` | Additional init containers on the API and Fusillade pods; native sidecars (`restartPolicy: Always`) work too | `[]` |
136+
| `volumes` / `volumeMounts` | Additional volumes and dwctl container mounts on the API and Fusillade pods | `[]` |
137+
| `migrations.job.command` | Override the migration Job's command; its args stay `migrate` | `[]` |
138+
| `migrations.job.initContainers` | Additional init containers on the migration Job | `[]` |
139+
| `migrations.job.volumes` / `migrations.job.volumeMounts` | Additional volumes and mounts on the migration Job | `[]` |
140+
| `extraObjects` | Additional manifests rendered with the release as-is (not templated) | `[]` |
141+
127142
### Resources and Probes
128143

129144
| Parameter | Description | Default |

‎templates/_helpers.tpl‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ options renders byte-for-byte the same template as before this helper existed.
342342
securityContext:
343343
{{- toYaml . | nindent 8 }}
344344
{{- end }}
345+
{{- with $root.Values.initContainers }}
346+
initContainers:
347+
{{- toYaml . | nindent 8 }}
348+
{{- end }}
345349
containers:
346350
- name: control-layer
347351
{{- if $root.Values.rollout.enabled }}
@@ -359,6 +363,14 @@ options renders byte-for-byte the same template as before this helper existed.
359363
{{- end }}
360364
image: "{{ $root.Values.image.repository }}:{{ $root.Values.image.tag | default $root.Chart.AppVersion }}"
361365
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
366+
{{- with $root.Values.command }}
367+
command:
368+
{{- toYaml . | nindent 12 }}
369+
{{- end }}
370+
{{- with $root.Values.args }}
371+
args:
372+
{{- toYaml . | nindent 12 }}
373+
{{- end }}
362374
ports:
363375
- name: http
364376
containerPort: {{ $root.Values.service.port }}

‎templates/extra-objects.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- /* Additional manifests from .Values.extraObjects, rendered as-is: not
2+
passed through `tpl`, so their contents (e.g. another tool's templates) are
3+
left untouched. */ -}}
4+
{{- range .Values.extraObjects }}
5+
---
6+
{{ toYaml . }}
7+
{{- end }}

‎templates/fusillade/deployment.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ spec:
4444
securityContext:
4545
{{- toYaml . | nindent 8 }}
4646
{{- end }}
47+
{{- with $root.Values.initContainers }}
48+
initContainers:
49+
{{- toYaml . | nindent 8 }}
50+
{{- end }}
4751
containers:
4852
- name: fusillade
4953
{{- with (get $config "securityContext" | default $fusillade.securityContext | default $root.Values.securityContext) }}
@@ -52,6 +56,14 @@ spec:
5256
{{- end }}
5357
image: "{{ get $image "repository" | default (get $baseImage "repository") | default $root.Values.image.repository }}:{{ get $image "tag" | default (get $baseImage "tag") | default $root.Values.image.tag | default $root.Chart.AppVersion }}"
5458
imagePullPolicy: {{ get $image "pullPolicy" | default (get $baseImage "pullPolicy") | default $root.Values.image.pullPolicy }}
59+
{{- with $root.Values.command }}
60+
command:
61+
{{- toYaml . | nindent 12 }}
62+
{{- end }}
63+
{{- with $root.Values.args }}
64+
args:
65+
{{- toYaml . | nindent 12 }}
66+
{{- end }}
5567
ports:
5668
- name: http
5769
containerPort: {{ $root.Values.service.port }}

‎templates/migrations/job.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ spec:
8585
securityContext:
8686
{{- toYaml . | nindent 8 }}
8787
{{- end }}
88+
{{- with .Values.migrations.job.initContainers }}
89+
initContainers:
90+
{{- toYaml . | nindent 8 }}
91+
{{- end }}
8892
containers:
8993
- name: migrate
9094
{{- with .Values.securityContext }}
@@ -93,6 +97,10 @@ spec:
9397
{{- end }}
9498
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
9599
imagePullPolicy: {{ .Values.image.pullPolicy }}
100+
{{- with .Values.migrations.job.command }}
101+
command:
102+
{{- toYaml . | nindent 12 }}
103+
{{- end }}
96104
args:
97105
- migrate
98106
{{- /*

‎tests/standard_hooks_test.yaml‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
suite: test standard hooks (command, args, initContainers, extraObjects)
2+
templates:
3+
- deployment.yaml
4+
- fusillade/deployment.yaml
5+
- migrations/job.yaml
6+
- extra-objects.yaml
7+
- configmap.yaml
8+
- secret.yaml
9+
- migrations/config.yaml
10+
- migrations/secret.yaml
11+
tests:
12+
- it: leaves command, args and init containers unset by default
13+
template: deployment.yaml
14+
asserts:
15+
- notExists:
16+
path: spec.template.spec.containers[0].command
17+
- notExists:
18+
path: spec.template.spec.containers[0].args
19+
- notExists:
20+
path: spec.template.spec.initContainers
21+
22+
- it: sets command, args and init containers on the API pods
23+
template: deployment.yaml
24+
set:
25+
command: ["/tools/launcher", "--", "./dwctl"]
26+
args: ["--validate"]
27+
initContainers:
28+
- name: fetch-tools
29+
image: example/tools:1.0
30+
- name: helper
31+
image: example/helper:1.0
32+
restartPolicy: Always
33+
asserts:
34+
- equal:
35+
path: spec.template.spec.containers[0].command
36+
value: ["/tools/launcher", "--", "./dwctl"]
37+
- equal:
38+
path: spec.template.spec.containers[0].args
39+
value: ["--validate"]
40+
- equal:
41+
path: spec.template.spec.initContainers[0].name
42+
value: fetch-tools
43+
- equal:
44+
path: spec.template.spec.initContainers[1].restartPolicy
45+
value: Always
46+
47+
- it: sets the same command and init containers on the Fusillade pods
48+
template: fusillade/deployment.yaml
49+
set:
50+
fusillade.enabled: true
51+
command: ["/tools/launcher", "--", "./dwctl"]
52+
initContainers:
53+
- name: fetch-tools
54+
image: example/tools:1.0
55+
asserts:
56+
- equal:
57+
path: spec.template.spec.containers[0].command
58+
value: ["/tools/launcher", "--", "./dwctl"]
59+
- equal:
60+
path: spec.template.spec.initContainers[0].name
61+
value: fetch-tools
62+
63+
- it: gives the migration Job its own command and init containers, keeping args migrate
64+
template: migrations/job.yaml
65+
set:
66+
migrations.job.enabled: true
67+
postgresql.enabled: false
68+
secrets.controlLayer.data.DATABASE_URL: "postgres://db.example.com/control_layer"
69+
command: ["/not/for/the/job"]
70+
migrations.job.command: ["/tools/launcher", "--", "./dwctl"]
71+
migrations.job.initContainers:
72+
- name: fetch-tools
73+
image: example/tools:1.0
74+
asserts:
75+
- equal:
76+
path: spec.template.spec.containers[0].command
77+
value: ["/tools/launcher", "--", "./dwctl"]
78+
- equal:
79+
path: spec.template.spec.containers[0].args
80+
value: ["migrate"]
81+
- equal:
82+
path: spec.template.spec.initContainers[0].name
83+
value: fetch-tools
84+
85+
- it: leaves the migration Job's command unset by default
86+
template: migrations/job.yaml
87+
set:
88+
migrations.job.enabled: true
89+
postgresql.enabled: false
90+
secrets.controlLayer.data.DATABASE_URL: "postgres://db.example.com/control_layer"
91+
command: ["/not/for/the/job"]
92+
asserts:
93+
- notExists:
94+
path: spec.template.spec.containers[0].command
95+
- notExists:
96+
path: spec.template.spec.initContainers
97+
98+
- it: renders nothing for extraObjects by default
99+
template: extra-objects.yaml
100+
asserts:
101+
- hasDocuments:
102+
count: 0
103+
104+
- it: renders extraObjects as-is, leaving template syntax untouched
105+
template: extra-objects.yaml
106+
set:
107+
extraObjects:
108+
- apiVersion: v1
109+
kind: ConfigMap
110+
metadata:
111+
name: launcher-config
112+
data:
113+
config.yaml: "value: {{ .Value }}"
114+
asserts:
115+
- hasDocuments:
116+
count: 1
117+
- isKind:
118+
of: ConfigMap
119+
- equal:
120+
path: data["config.yaml"]
121+
value: "value: {{ .Value }}"

‎values.yaml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ migrations:
226226
podLabels: {}
227227
volumes: []
228228
volumeMounts: []
229+
# Override the migrate container's command; its args stay `migrate`.
230+
command: []
231+
# Additional init containers on the Job's pod.
232+
initContainers: []
229233
# DWCTL_MIGRATIONS__MODE for application pods when the Job is enabled.
230234
# `check` is the only mode that makes the Job meaningful; `run` reverts to
231235
# in-pod migrations while keeping the Job (useful during the first
@@ -263,6 +267,20 @@ readinessProbe:
263267
# timeoutSeconds: 5
264268
# failureThreshold: 18 # 90 seconds max startup
265269

270+
# Override the dwctl container's command on the API and Fusillade pods (the
271+
# image's entrypoint is ./dwctl), e.g. to start it through a launcher:
272+
# command: ["/tools/launcher", "--", "./dwctl"]
273+
# The migration Job has its own: migrations.job.command.
274+
command: []
275+
276+
# Override the dwctl container's args on the API and Fusillade pods.
277+
args: []
278+
279+
# Additional init containers on the API and Fusillade pods. Native sidecars
280+
# (an init container with restartPolicy: Always) work too. The migration Job
281+
# has its own: migrations.job.initContainers.
282+
initContainers: []
283+
266284
# Additional volumes on the output Deployment definition.
267285
volumes: []
268286
# - name: foo
@@ -651,3 +669,12 @@ keystore:
651669
nodeSelector: {}
652670
affinity: {}
653671
tolerations: {}
672+
673+
# Additional manifests to render with the release, as-is (not templated).
674+
extraObjects: []
675+
# - apiVersion: v1
676+
# kind: ConfigMap
677+
# metadata:
678+
# name: my-config
679+
# data:
680+
# key: value

0 commit comments

Comments
 (0)