clients support extraVolumes
This commit is contained in:
parent
2488f92a23
commit
2434fe5a43
4 changed files with 143 additions and 0 deletions
|
@ -37,6 +37,15 @@ spec:
|
|||
- name: config
|
||||
configMap:
|
||||
name: {{ template "consul.fullname" . }}-client-config
|
||||
{{- range .Values.client.extraVolumes }}
|
||||
- name: userconfig-{{ .name }}
|
||||
{{ .type }}:
|
||||
{{- if (eq .type "configMap") }}
|
||||
name: {{ .name }}
|
||||
{{- else if (eq .type "secret") }}
|
||||
secretName: {{ .name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
containers:
|
||||
- name: consul
|
||||
|
@ -61,6 +70,11 @@ spec:
|
|||
-bind=0.0.0.0 \
|
||||
-client=0.0.0.0 \
|
||||
-config-dir=/consul/config \
|
||||
{{- range .Values.client.extraVolumes }}
|
||||
{{- if .load }}
|
||||
-config-dir=/consul/userconfig/{{ .name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
-datacenter={{ .Values.global.datacenter }} \
|
||||
-data-dir=/consul/data \
|
||||
{{- if (.Values.client.join) and (gt (len .Values.client.join) 0) }}
|
||||
|
@ -80,6 +94,11 @@ spec:
|
|||
mountPath: /consul/data
|
||||
- name: config
|
||||
mountPath: /consul/config
|
||||
{{- range .Values.client.extraVolumes }}
|
||||
- name: userconfig-{{ .name }}
|
||||
readOnly: true
|
||||
mountPath: /consul/userconfig/{{ .name }}
|
||||
{{- end }}
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
|
|
|
@ -71,3 +71,108 @@ load _helpers
|
|||
yq -r '.spec.updateStrategy' | tee /dev/stderr)
|
||||
[ "${actual}" = "null" ]
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# extraVolumes
|
||||
|
||||
@test "client/DaemonSet: adds extra volume" {
|
||||
cd `chart_dir`
|
||||
|
||||
# Test that it defines it
|
||||
local object=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.volumes[] | select(.name == "userconfig-foo")' | tee /dev/stderr)
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.configMap.name' | tee /dev/stderr)
|
||||
[ "${actual}" = "foo" ]
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.configMap.secretName' | tee /dev/stderr)
|
||||
[ "${actual}" = "null" ]
|
||||
|
||||
# Test that it mounts it
|
||||
local object=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].volumeMounts[] | select(.name == "userconfig-foo")' | tee /dev/stderr)
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.readOnly' | tee /dev/stderr)
|
||||
[ "${actual}" = "true" ]
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.mountPath' | tee /dev/stderr)
|
||||
[ "${actual}" = "/consul/userconfig/foo" ]
|
||||
|
||||
# Doesn't load it
|
||||
local actual=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].command | map(select(test("userconfig"))) | length' | tee /dev/stderr)
|
||||
[ "${actual}" = "0" ]
|
||||
}
|
||||
|
||||
@test "client/DaemonSet: adds extra secret volume" {
|
||||
cd `chart_dir`
|
||||
|
||||
# Test that it defines it
|
||||
local object=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=secret' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.volumes[] | select(.name == "userconfig-foo")' | tee /dev/stderr)
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.secret.name' | tee /dev/stderr)
|
||||
[ "${actual}" = "null" ]
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.secret.secretName' | tee /dev/stderr)
|
||||
[ "${actual}" = "foo" ]
|
||||
|
||||
# Test that it mounts it
|
||||
local object=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].volumeMounts[] | select(.name == "userconfig-foo")' | tee /dev/stderr)
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.readOnly' | tee /dev/stderr)
|
||||
[ "${actual}" = "true" ]
|
||||
|
||||
local actual=$(echo $object |
|
||||
yq -r '.mountPath' | tee /dev/stderr)
|
||||
[ "${actual}" = "/consul/userconfig/foo" ]
|
||||
|
||||
# Doesn't load it
|
||||
local actual=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].command | map(select(test("userconfig"))) | length' | tee /dev/stderr)
|
||||
[ "${actual}" = "0" ]
|
||||
}
|
||||
|
||||
@test "client/DaemonSet: adds loadable volume" {
|
||||
cd `chart_dir`
|
||||
local actual=$(helm template \
|
||||
-x templates/client-daemonset.yaml \
|
||||
--set 'client.extraVolumes[0].type=configMap' \
|
||||
--set 'client.extraVolumes[0].name=foo' \
|
||||
--set 'client.extraVolumes[0].load=true' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].command | map(select(test("/consul/userconfig/foo"))) | length' | tee /dev/stderr)
|
||||
[ "${actual}" = "1" ]
|
||||
}
|
||||
|
|
|
@ -185,3 +185,14 @@ load _helpers
|
|||
[ "${actual}" = "0" ]
|
||||
}
|
||||
|
||||
@test "server/StatefulSet: adds loadable volume" {
|
||||
cd `chart_dir`
|
||||
local actual=$(helm template \
|
||||
-x templates/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.extraVolumes[0].name=foo' \
|
||||
--set 'server.extraVolumes[0].load=true' \
|
||||
. | tee /dev/stderr |
|
||||
yq -r '.spec.template.spec.containers[0].command | map(select(test("/consul/userconfig/foo"))) | length' | tee /dev/stderr)
|
||||
[ "${actual}" = "1" ]
|
||||
}
|
||||
|
|
|
@ -86,6 +86,14 @@ client:
|
|||
extraConfig: |
|
||||
{}
|
||||
|
||||
# extraVolumes is a list of extra volumes to mount. These will be exposed
|
||||
# to Consul in the path `/consul/userconfig/<name>/`. The value below is
|
||||
# an array of objects, examples are shown below.
|
||||
extraVolumes: []
|
||||
# - type: secret (or "configMap")
|
||||
# name: my-secret
|
||||
# load: false # if true, will add to `-config-dir` to load by Consul
|
||||
|
||||
# ConnectInject will enable the automatic Connect sidecar injector.
|
||||
connectInject:
|
||||
enabled: false # "-" disable this by default for now until the image is public
|
||||
|
|
Loading…
Reference in a new issue