add initcontainers support (#63)
Co-authored-by: Youcef Guichi <youcef@gimlet.io>
This commit is contained in:
@@ -2,21 +2,14 @@
|
||||
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets }}
|
||||
volumeMounts: &volumeMounts
|
||||
{{- range .Values.volumes }}
|
||||
|
||||
{{- $volumeName := .name -}}
|
||||
{{- if .existingConfigMap }}
|
||||
{{- $volumeName = .existingConfigMap -}}
|
||||
{{- end }}
|
||||
{{- if .fileName }}
|
||||
{{- $volumeName = include "common.robustName" .fileName -}}
|
||||
{{- end }}
|
||||
|
||||
- name: {{ $volumeName }}
|
||||
{{- if not (hasPrefix "init-" .name) }}
|
||||
- name: {{ .name }}
|
||||
mountPath: {{ .path }}
|
||||
{{- if .subPath }}
|
||||
subPath: {{ .subPath }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- range .Values.sealedFileSecrets }}
|
||||
- name: {{ .name }}
|
||||
mountPath: {{ .path }}
|
||||
|
||||
@@ -2,16 +2,7 @@
|
||||
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets }}
|
||||
volumes:
|
||||
{{- range .Values.volumes }}
|
||||
|
||||
{{- $volumeName := .name -}}
|
||||
{{- if .existingConfigMap }}
|
||||
{{- $volumeName = .existingConfigMap -}}
|
||||
{{- end }}
|
||||
{{- if .fileName }}
|
||||
{{- $volumeName = include "common.robustName" .fileName -}}
|
||||
{{- end }}
|
||||
|
||||
- name: {{ $volumeName }}
|
||||
- name: {{ .name }}
|
||||
{{- if .emptyDir }}
|
||||
emptyDir: {}
|
||||
{{- else if .existingConfigMap }}
|
||||
@@ -19,7 +10,7 @@ volumes:
|
||||
name: {{ .existingConfigMap }}
|
||||
{{- else if .fileName }}
|
||||
configMap:
|
||||
name: {{ $volumeName }}
|
||||
name: {{ template "common.robustName" .fileName }}
|
||||
{{- else if .hostPath }}
|
||||
hostPath:
|
||||
path: {{ .hostPath.path }}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -50,6 +50,25 @@ spec:
|
||||
{{- if .Values.serviceAccount }}
|
||||
serviceAccountName: {{ .Values.serviceAccount }}
|
||||
{{- end }}
|
||||
initContainers:
|
||||
{{- range .Values.initContainers }}
|
||||
- name: {{ .name }}
|
||||
image: "{{ .image }}:{{ .tag }}"
|
||||
imagePullPolicy: {{ .imagePullPolicy | default "IfNotPresent" }}
|
||||
{{- if .command }}
|
||||
command:
|
||||
- {{ $.Values.shell }}
|
||||
- -c
|
||||
- {{ .command | quote}}
|
||||
{{- end }}
|
||||
volumeMounts:
|
||||
{{- range $.Values.volumes }}
|
||||
{{if (or (hasPrefix "shared-" .name) (hasPrefix "init-" .name))}}
|
||||
- mountPath: {{ .path }}
|
||||
name: {{ .name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: {{ template "robustName" .Release.Name }}
|
||||
securityContext: &securityContext
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
suite: test deployment
|
||||
templates:
|
||||
- deployment.yaml
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should set name, image and tag
|
||||
set:
|
||||
initContainers:
|
||||
- name: pod1
|
||||
image: nginx
|
||||
tag: 1.2.2
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].name
|
||||
value: pod1
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].image
|
||||
value: "nginx:1.2.2"
|
||||
- it: Should set command
|
||||
set:
|
||||
initContainers:
|
||||
- command: "while true; do date; sleep 2; done &&
|
||||
ls /data &&
|
||||
printf something"
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].command
|
||||
value: ['/bin/sh', '-c', 'while true; do date; sleep 2; done && ls /data && printf something']
|
||||
|
||||
|
||||
|
||||
@@ -137,25 +137,27 @@ tests:
|
||||
set:
|
||||
volumes:
|
||||
- existingConfigMap: my-configmap
|
||||
name: volume-name
|
||||
path: /randomPath/app.conf
|
||||
subPath: app.conf
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.volumes
|
||||
value:
|
||||
- name: my-configmap
|
||||
- name: volume-name
|
||||
configMap:
|
||||
name: my-configmap
|
||||
- equal:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
value:
|
||||
- name: my-configmap
|
||||
- name: volume-name
|
||||
mountPath: /randomPath/app.conf
|
||||
subPath: app.conf
|
||||
- it: Should use a configmap with custom value
|
||||
set:
|
||||
volumes:
|
||||
- fileName: myfile.conf
|
||||
- name: volume-name
|
||||
fileName: myfile.conf
|
||||
fileContent: |
|
||||
blablabla
|
||||
bla
|
||||
@@ -165,12 +167,55 @@ tests:
|
||||
- equal:
|
||||
path: spec.template.spec.volumes
|
||||
value:
|
||||
- name: myfile-conf
|
||||
- name: volume-name
|
||||
configMap:
|
||||
name: myfile-conf
|
||||
- equal:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
value:
|
||||
- name: myfile-conf
|
||||
- name: volume-name
|
||||
mountPath: /randomPath/myfile.conf
|
||||
subPath: myfile.conf
|
||||
- it: Should mount a volume only for the init container
|
||||
set:
|
||||
initContainers:
|
||||
- name : pod
|
||||
volumes:
|
||||
- name: init-volume
|
||||
path: /data
|
||||
emptyDir: true
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.volumes
|
||||
value:
|
||||
- name: init-volume
|
||||
emptyDir: {}
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].volumeMounts
|
||||
value:
|
||||
- name: init-volume
|
||||
mountPath: /data
|
||||
- notEqual:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
value:
|
||||
- name: init-volume
|
||||
emptyDir: {}
|
||||
- it: Should mount a shared volume between the main container and the init container
|
||||
set:
|
||||
initContainers:
|
||||
- name: pod
|
||||
volumes:
|
||||
- name: shared-volume
|
||||
path: /data
|
||||
emptyDir: true
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.template.spec.initContainers[0].volumeMounts
|
||||
value:
|
||||
- name: shared-volume
|
||||
mountPath: /data
|
||||
- equal:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
value:
|
||||
- name: shared-volume
|
||||
mountPath: /data
|
||||
|
||||
@@ -84,6 +84,53 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"initContainers": {
|
||||
"$id": "#/properties/initcontainers",
|
||||
"type": "array",
|
||||
"title": "Init Containers",
|
||||
"default": [],
|
||||
"additionalItems": true,
|
||||
"items": {
|
||||
"$id": "#/properties/initcontainers/items",
|
||||
"type": "object",
|
||||
"anyOf": [
|
||||
{
|
||||
"id": "#/properties/volumes/oneOf/0",
|
||||
"title": "InitContainer",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"title": "Name",
|
||||
"description": "The name of the init container"
|
||||
},
|
||||
"image": {
|
||||
"type": "string",
|
||||
"title": "Image"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string",
|
||||
"title": "Tag"
|
||||
},
|
||||
"imagePullPolicy": {
|
||||
"type": "string",
|
||||
"title": "Command",
|
||||
"default": "IfNotPresent"
|
||||
},
|
||||
"command": {
|
||||
"type": "string",
|
||||
"title": "Command"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"image",
|
||||
"tag"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"replicas": {
|
||||
"$id": "#/properties/replicas",
|
||||
"type": "integer",
|
||||
|
||||
Reference in New Issue
Block a user