Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for more flexible volume mounts e.g. for use with init containers #314

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ extra volumes the user may have specified (such as a secret with TLS).
secretName: {{ .name }}
{{- end }}
{{- end }}
{{- if .Values.server.volumes }}
{{- toYaml .Values.server.volumes | nindent 8}}
{{- end }}
{{- end -}}

{{/*
Expand Down Expand Up @@ -159,6 +162,9 @@ based on the mode configured.
readOnly: true
mountPath: {{ .path | default "/vault/userconfig" }}/{{ .name }}
{{- end }}
{{- if .Values.server.volumeMounts }}
{{- toYaml .Values.server.volumeMounts | nindent 12}}
{{- end }}
{{- end -}}

{{/*
Expand Down
47 changes: 45 additions & 2 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ load _helpers
#--------------------------------------------------------------------
# extraVolumes

@test "server/standalone-StatefulSet: adds extra volume" {
@test "server/standalone-StatefulSet: server.extraVolumes adds extra volume" {
cd `chart_dir`

# Test that it defines it
Expand Down Expand Up @@ -293,7 +293,7 @@ load _helpers
[ "${actual}" = "/vault/userconfig/foo" ]
}

@test "server/standalone-StatefulSet: adds extra secret volume" {
@test "server/standalone-StatefulSet: server.extraVolumes adds extra secret volume" {
cd `chart_dir`

# Test that it defines it
Expand Down Expand Up @@ -370,6 +370,49 @@ load _helpers
yq -r '.spec.template.spec.containers[0].volumeMounts[] | select(.name == "audit")' | tee /dev/stderr)
}

#--------------------------------------------------------------------
# volumes

@test "server/standalone-StatefulSet: server.volumes adds volume" {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.volumes[0].name=plugins' \
--set 'server.volumes[0].emptyDir=\{\}' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.volumes[] | select(.name == "plugins")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.emptyDir' | tee /dev/stderr)
[ "${actual}" = "{}" ]
}

#--------------------------------------------------------------------
# volumeMounts

@test "server/standalone-StatefulSet: server.volumeMounts adds volumeMount" {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.volumeMounts[0].name=plugins' \
--set 'server.volumeMounts[0].mountPath=/usr/local/libexec/vault' \
--set 'server.volumeMounts[0].readOnly=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].volumeMounts[] | select(.name == "plugins")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.mountPath' | tee /dev/stderr)
[ "${actual}" = "/usr/local/libexec/vault" ]

local actual=$(echo $object |
yq -r '.readOnly' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# extraEnvironmentVars

Expand Down
30 changes: 30 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ server:
# This is useful if you need to run a script to provision TLS certificates or
# write out configuration files in a dynamic way.
extraInitContainers: null
# # This example installs a plugin pulled from github into the /usr/local/libexec/vault/oauthapp folder,
# # which is defined in the volumes value.
# - name: oauthapp
# image: "alpine"
# command: [sh, -c]
# args:
# - cd /tmp &&
# wget https://github.com/puppetlabs/vault-plugin-secrets-oauthapp/releases/download/v1.2.0/vault-plugin-secrets-oauthapp-v1.2.0-linux-amd64.tar.xz -O oauthapp.xz &&
# tar -xf oauthapp.xz &&
# mv vault-plugin-secrets-oauthapp-v1.2.0-linux-amd64 /usr/local/libexec/vault/oauthapp &&
# chmod +x /usr/local/libexec/vault/oauthapp
# volumeMounts:
# - name: plugins
# mountPath: /usr/local/libexec/vault

# extraContainers is a list of sidecar containers. Specified as a YAML list.
extraContainers: null
Expand Down Expand Up @@ -210,6 +224,22 @@ server:
# name: my-secret
# path: null # default is `/vault/userconfig`

# volumes is a list of volumes made available to all containers. These are rendered
# via toYaml rather than pre-processed like the extraVolumes value.
# The purpose is to make it easy to share volumes between containers.
volumes: null
# - name: plugins
# emptyDir: {}

# volumeMounts is a list of volumeMounts for the main server container. These are rendered
# via toYaml rather than pre-processed like the extraVolumes value.
# The purpose is to make it easy to share volumes between containers.
volumeMounts: null
# - mountPath: /usr/local/libexec/vault
# name: plugins
# readOnly: true


# Affinity Settings
# Commenting out or setting as empty the affinity variable, will allow
# deployment to single node services such as Minikube
Expand Down