Support extraVolumes for server, will add for client soon
This commit is contained in:
parent
c9a5588264
commit
2488f92a23
3 changed files with 124 additions and 0 deletions
|
@ -51,6 +51,15 @@ spec:
|
|||
- name: config
|
||||
configMap:
|
||||
name: {{ template "consul.fullname" . }}-server-config
|
||||
{{- range .Values.server.extraVolumes }}
|
||||
- name: userconfig-{{ .name }}
|
||||
{{ .type }}:
|
||||
{{- if (eq .type "configMap") }}
|
||||
name: {{ .name }}
|
||||
{{- else if (eq .type "secret") }}
|
||||
secretName: {{ .name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: consul
|
||||
image: "{{ default .Values.global.image .Values.server.image }}"
|
||||
|
@ -75,6 +84,11 @@ spec:
|
|||
-bootstrap-expect={{ .Values.server.bootstrapExpect }} \
|
||||
-client=0.0.0.0 \
|
||||
-config-dir=/consul/config \
|
||||
{{- range .Values.server.extraVolumes }}
|
||||
{{- if .load }}
|
||||
-config-dir=/consul/userconfig/{{ .name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
-datacenter={{ .Values.global.datacenter }} \
|
||||
-data-dir=/consul/data \
|
||||
-domain={{ .Values.global.domain }} \
|
||||
|
@ -93,6 +107,11 @@ spec:
|
|||
mountPath: /consul/data
|
||||
- name: config
|
||||
mountPath: /consul/config
|
||||
{{- range .Values.server.extraVolumes }}
|
||||
- name: userconfig-{{ .name }}
|
||||
readOnly: true
|
||||
mountPath: /consul/userconfig/{{ .name }}
|
||||
{{- end }}
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
|
|
|
@ -63,6 +63,9 @@ load _helpers
|
|||
[ "${actual}" = "bar" ]
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# updateStrategy
|
||||
|
||||
@test "server/StatefulSet: no updateStrategy when not updating" {
|
||||
cd `chart_dir`
|
||||
local actual=$(helm template \
|
||||
|
@ -88,3 +91,97 @@ load _helpers
|
|||
yq -r '.spec.updateStrategy.rollingUpdate.partition' | tee /dev/stderr)
|
||||
[ "${actual}" = "2" ]
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# extraVolumes
|
||||
|
||||
@test "server/StatefulSet: adds extra volume" {
|
||||
cd `chart_dir`
|
||||
|
||||
# Test that it defines it
|
||||
local object=$(helm template \
|
||||
-x templates/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.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/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.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/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.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 "server/StatefulSet: adds extra secret volume" {
|
||||
cd `chart_dir`
|
||||
|
||||
# Test that it defines it
|
||||
local object=$(helm template \
|
||||
-x templates/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=secret' \
|
||||
--set 'server.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/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.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/server-statefulset.yaml \
|
||||
--set 'server.extraVolumes[0].type=configMap' \
|
||||
--set 'server.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" ]
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,14 @@ server:
|
|||
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
|
||||
|
||||
# Client, when enabled, configures Consul clients to run on every node
|
||||
# within the Kube cluster. The current deployment model follows a traditional
|
||||
# DC where a single agent is deployed per node.
|
||||
|
|
Loading…
Reference in a new issue