Skip to content

Commit a797b10

Browse files
committed
test: add unit tests for volume and volumeMount management
- tests/volumes_test.yaml: 9 tests covering deployment, worker, cron, job - extra volumes/volumeMounts are rendered in all workload templates - extra mounts are appended after php-ini when both are set - volumes section is omitted when nothing is configured - Fix deployment.yaml: make volumeMounts and volumes sections conditional to avoid empty keys in the rendered manifest
1 parent acff677 commit a797b10

2 files changed

Lines changed: 230 additions & 0 deletions

File tree

charts/frankenphp/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spec:
4848
env:
4949
{{- toYaml . | nindent 12 }}
5050
{{- end }}
51+
{{- if or .Values.caddyfile .Values.php.ini .Values.volumeMounts }}
5152
volumeMounts:
5253
{{- if .Values.caddyfile }}
5354
- name: caddyfile
@@ -61,6 +62,7 @@ spec:
6162
{{- with .Values.volumeMounts }}
6263
{{- toYaml . | nindent 12 }}
6364
{{- end }}
65+
{{- end }}
6466
{{- with .Values.nodeSelector }}
6567
nodeSelector:
6668
{{- toYaml . | nindent 8 }}
@@ -73,6 +75,7 @@ spec:
7375
tolerations:
7476
{{- toYaml . | nindent 8 }}
7577
{{- end }}
78+
{{- if or .Values.caddyfile .Values.php.ini .Values.volumes }}
7679
volumes:
7780
{{- if .Values.caddyfile }}
7881
- name: caddyfile # To access this volume, this name must be used inside volumeMounts of the container
@@ -90,4 +93,5 @@ spec:
9093
{{- with .Values.volumes }}
9194
{{- toYaml . | nindent 8 }}
9295
{{- end }}
96+
{{- end }}
9397
{{- end }}
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
suite: Volume Management
2+
templates:
3+
- deployment.yaml
4+
- worker.yaml
5+
- crons.yaml
6+
- jobs.yaml
7+
8+
tests:
9+
# --- Deployment ---
10+
11+
- it: should mount extra volume in Deployment
12+
template: deployment.yaml
13+
set:
14+
volumes:
15+
- name: symfony-decrypt-key
16+
secret:
17+
secretName: symfony-secrets
18+
volumeMounts:
19+
- name: symfony-decrypt-key
20+
mountPath: /app/config/secrets/prod/prod.decrypt.private.php
21+
subPath: prod.decrypt.private.php
22+
readOnly: true
23+
asserts:
24+
- equal:
25+
path: spec.template.spec.volumes[0].name
26+
value: symfony-decrypt-key
27+
- equal:
28+
path: spec.template.spec.volumes[0].secret.secretName
29+
value: symfony-secrets
30+
- equal:
31+
path: spec.template.spec.containers[0].volumeMounts[0].name
32+
value: symfony-decrypt-key
33+
- equal:
34+
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
35+
value: /app/config/secrets/prod/prod.decrypt.private.php
36+
- equal:
37+
path: spec.template.spec.containers[0].volumeMounts[0].readOnly
38+
value: true
39+
40+
- it: should not add volumes section when volumes is empty in Deployment
41+
template: deployment.yaml
42+
asserts:
43+
- notExists:
44+
path: spec.template.spec.volumes
45+
46+
- it: should append extra volumeMount after php-ini in Deployment
47+
template: deployment.yaml
48+
set:
49+
php:
50+
ini: "memory_limit = 512M"
51+
volumes:
52+
- name: my-secret
53+
secret:
54+
secretName: my-secret
55+
volumeMounts:
56+
- name: my-secret
57+
mountPath: /app/secret
58+
asserts:
59+
- equal:
60+
path: spec.template.spec.containers[0].volumeMounts[0].name
61+
value: php-ini
62+
- equal:
63+
path: spec.template.spec.containers[0].volumeMounts[1].name
64+
value: my-secret
65+
- equal:
66+
path: spec.template.spec.volumes[0].name
67+
value: php-ini
68+
- equal:
69+
path: spec.template.spec.volumes[1].name
70+
value: my-secret
71+
72+
# --- Worker ---
73+
74+
- it: should mount extra volume in Worker
75+
template: worker.yaml
76+
set:
77+
consumers:
78+
- name: queue
79+
command: "php bin/console messenger:consume"
80+
volumes:
81+
- name: symfony-decrypt-key
82+
secret:
83+
secretName: symfony-secrets
84+
volumeMounts:
85+
- name: symfony-decrypt-key
86+
mountPath: /app/config/secrets/prod/prod.decrypt.private.php
87+
subPath: prod.decrypt.private.php
88+
readOnly: true
89+
asserts:
90+
- equal:
91+
path: spec.template.spec.volumes[0].name
92+
value: symfony-decrypt-key
93+
- equal:
94+
path: spec.template.spec.containers[0].volumeMounts[0].name
95+
value: symfony-decrypt-key
96+
- equal:
97+
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
98+
value: /app/config/secrets/prod/prod.decrypt.private.php
99+
100+
- it: should append extra volumeMount after php-ini in Worker
101+
template: worker.yaml
102+
set:
103+
consumers:
104+
- name: queue
105+
command: "php bin/console messenger:consume"
106+
php:
107+
ini: "memory_limit = 512M"
108+
volumes:
109+
- name: my-secret
110+
secret:
111+
secretName: my-secret
112+
volumeMounts:
113+
- name: my-secret
114+
mountPath: /app/secret
115+
asserts:
116+
- equal:
117+
path: spec.template.spec.containers[0].volumeMounts[0].name
118+
value: php-ini
119+
- equal:
120+
path: spec.template.spec.containers[0].volumeMounts[1].name
121+
value: my-secret
122+
- equal:
123+
path: spec.template.spec.volumes[0].name
124+
value: php-ini
125+
- equal:
126+
path: spec.template.spec.volumes[1].name
127+
value: my-secret
128+
129+
# --- CronJob ---
130+
131+
- it: should mount extra volume in CronJob
132+
template: crons.yaml
133+
set:
134+
crons:
135+
- name: my-cron
136+
command: "php bin/console app:run"
137+
schedule: "*/5 * * * *"
138+
volumes:
139+
- name: symfony-decrypt-key
140+
secret:
141+
secretName: symfony-secrets
142+
volumeMounts:
143+
- name: symfony-decrypt-key
144+
mountPath: /app/config/secrets/prod/prod.decrypt.private.php
145+
subPath: prod.decrypt.private.php
146+
readOnly: true
147+
asserts:
148+
- equal:
149+
path: spec.jobTemplate.spec.template.spec.volumes[0].name
150+
value: symfony-decrypt-key
151+
- equal:
152+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].name
153+
value: symfony-decrypt-key
154+
- equal:
155+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].mountPath
156+
value: /app/config/secrets/prod/prod.decrypt.private.php
157+
158+
- it: should not add volumes in CronJob when volumes is empty
159+
template: crons.yaml
160+
set:
161+
crons:
162+
- name: my-cron
163+
command: "php bin/console app:run"
164+
schedule: "*/5 * * * *"
165+
asserts:
166+
- notExists:
167+
path: spec.jobTemplate.spec.template.spec.volumes
168+
- notExists:
169+
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts
170+
171+
# --- Job ---
172+
173+
- it: should mount extra volume in Job
174+
template: jobs.yaml
175+
set:
176+
jobs:
177+
- name: migrate
178+
command: "php bin/console doctrine:migrations:migrate"
179+
volumes:
180+
- name: symfony-decrypt-key
181+
secret:
182+
secretName: symfony-secrets
183+
volumeMounts:
184+
- name: symfony-decrypt-key
185+
mountPath: /app/config/secrets/prod/prod.decrypt.private.php
186+
subPath: prod.decrypt.private.php
187+
readOnly: true
188+
asserts:
189+
- equal:
190+
path: spec.template.spec.volumes[0].name
191+
value: symfony-decrypt-key
192+
- equal:
193+
path: spec.template.spec.containers[0].volumeMounts[0].name
194+
value: symfony-decrypt-key
195+
- equal:
196+
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
197+
value: /app/config/secrets/prod/prod.decrypt.private.php
198+
199+
- it: should append extra volumeMount after php-ini in Job
200+
template: jobs.yaml
201+
set:
202+
jobs:
203+
- name: migrate
204+
command: "php bin/console doctrine:migrations:migrate"
205+
php:
206+
ini: "memory_limit = 512M"
207+
volumes:
208+
- name: my-secret
209+
secret:
210+
secretName: my-secret
211+
volumeMounts:
212+
- name: my-secret
213+
mountPath: /app/secret
214+
asserts:
215+
- equal:
216+
path: spec.template.spec.containers[0].volumeMounts[0].name
217+
value: php-ini
218+
- equal:
219+
path: spec.template.spec.containers[0].volumeMounts[1].name
220+
value: my-secret
221+
- equal:
222+
path: spec.template.spec.volumes[0].name
223+
value: php-ini
224+
- equal:
225+
path: spec.template.spec.volumes[1].name
226+
value: my-secret

0 commit comments

Comments
 (0)