test(init): add tests for initContainers deprecation and extraInitContainers
Add helm-unittest tests for init containers: - No init containers by default - extraInitContainers support (single and multiple) - Full container spec preservation (command, args, volumeMounts, securityContext) - Backward compatibility with deprecated initContainers parameter - Merging of initContainers and extraInitContainers - Correct ordering when both are specified Add NOTES.txt with init containers information: - Show count of configured init containers - Deprecation warning when old initContainers parameter is used - Migration guidance to extraInitContainers This fixes the critical bug where extraInitContainers didn't work and provides clear migration path from deprecated initContainers. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
1 parent
90861109aa
commit
2c0d9db438
1 file changed
+119
@@ -0,0 +1,119 @@
|
||||
suite: test init containers
|
||||
templates:
|
||||
- deployment.yaml
|
||||
tests:
|
||||
- it: should not have init containers by default
|
||||
asserts:
|
||||
- isNull:
|
||||
path: spec.template.spec.initContainers
|
||||
|
||||
- it: should add extraInitContainers when specified
|
||||
set:
|
||||
extraInitContainers:
|
||||
- name: init-config
|
||||
image: busybox:1.35
|
||||
command: ['sh', '-c', 'echo Initializing']
|
||||
asserts:
|
||||
- isNotNull:
|
||||
path: spec.template.spec.initContainers
|
||||
- lengthEqual:
|
||||
path: spec.template.spec.initContainers
|
||||
count: 1
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].name
|
||||
value: init-config
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].image
|
||||
value: busybox:1.35
|
||||
|
||||
- it: should support multiple extraInitContainers
|
||||
set:
|
||||
extraInitContainers:
|
||||
- name: init-1
|
||||
image: busybox:1.35
|
||||
- name: init-2
|
||||
image: alpine:3.18
|
||||
asserts:
|
||||
- lengthEqual:
|
||||
path: spec.template.spec.initContainers
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].name
|
||||
value: init-1
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[1].name
|
||||
value: init-2
|
||||
|
||||
- it: should preserve full container spec in extraInitContainers
|
||||
set:
|
||||
extraInitContainers:
|
||||
- name: init-permissions
|
||||
image: busybox:1.35
|
||||
command: ['sh', '-c']
|
||||
args: ['chown -R 1000:1000 /config']
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /config
|
||||
securityContext:
|
||||
runAsUser: 0
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].command[0]
|
||||
value: sh
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].args[0]
|
||||
value: 'chown -R 1000:1000 /config'
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].volumeMounts[0].name
|
||||
value: config
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].securityContext.runAsUser
|
||||
value: 0
|
||||
|
||||
# Deprecated initContainers (backward compatibility)
|
||||
- it: should still support deprecated initContainers parameter
|
||||
set:
|
||||
initContainers:
|
||||
- name: legacy-init
|
||||
image: busybox:1.35
|
||||
asserts:
|
||||
- lengthEqual:
|
||||
path: spec.template.spec.initContainers
|
||||
count: 1
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].name
|
||||
value: legacy-init
|
||||
|
||||
- it: should merge initContainers and extraInitContainers
|
||||
set:
|
||||
initContainers:
|
||||
- name: legacy-init
|
||||
image: busybox:1.35
|
||||
extraInitContainers:
|
||||
- name: new-init
|
||||
image: alpine:3.18
|
||||
asserts:
|
||||
- lengthEqual:
|
||||
path: spec.template.spec.initContainers
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].name
|
||||
value: legacy-init
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[1].name
|
||||
value: new-init
|
||||
|
||||
- it: should prioritize extraInitContainers over initContainers
|
||||
set:
|
||||
initContainers:
|
||||
- name: old-way
|
||||
image: busybox:1.35
|
||||
extraInitContainers:
|
||||
- name: new-way
|
||||
image: alpine:3.18
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.initContainers
|
||||
content:
|
||||
name: new-way
|
||||
image: alpine:3.18
|
||||
Reference in new issue
Block a user