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

Fix yaml upon empty volumeMounts or volumes #855

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions templates/tests/server-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ spec:
fi

exit 0
{{- if .Values.server.volumeMounts }}
volumeMounts:
{{- if .Values.server.volumeMounts }}
{{- toYaml .Values.server.volumeMounts | nindent 8}}
{{- end }}
{{- toYaml .Values.server.volumeMounts | nindent 8}}
{{- end }}
{{- if .Values.server.volumes }}
volumes:
{{- if .Values.server.volumes }}
{{- toYaml .Values.server.volumes | nindent 4}}
{{- end }}
{{- toYaml .Values.server.volumes | nindent 4}}
{{- end }}
restartPolicy: Never
{{- end }}
{{- end }}
38 changes: 31 additions & 7 deletions test/unit/server-test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,23 @@ load _helpers
. | tee /dev/stderr |
yq -r '.spec.volumes[] | select(.name == "plugins")' | tee /dev/stderr)

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

@test "server/standalone-server-test-Pod: no server.volumes adds no volumes" {
cd `chart_dir`

# Test that it defines it
local actual=$(helm template \
--show-only templates/tests/server-test.yaml \
. | tee /dev/stderr |
yq -r '.spec.volumes' | tee /dev/stderr)

[ "${actual}" = "null" ]
}

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

Expand All @@ -232,15 +244,27 @@ load _helpers
. | tee /dev/stderr |
yq -r '.spec.containers[0].volumeMounts[] | select(.name == "plugins")' | tee /dev/stderr)

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

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

@test "server/standalone-server-test-Pod: no server.volumeMounts adds no volumeMounts" {
cd `chart_dir`

# Test that it defines it
local actual=$(helm template \
--show-only templates/tests/server-test.yaml \
. | tee /dev/stderr |
yq -r '.spec.containers[0].volumeMounts' | tee /dev/stderr)

[ "${actual}" = "null" ]
}

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

Expand All @@ -254,11 +278,11 @@ load _helpers
. | tee /dev/stderr |
yq -r '.spec.containers[0].env' | tee /dev/stderr)

local name=$(echo $object |
local name=$(echo "$object" |
yq -r 'map(select(.name=="FOO")) | .[] .value' | tee /dev/stderr)
[ "${name}" = "bar" ]

local name=$(echo $object |
local name=$(echo "$object" |
yq -r 'map(select(.name=="FOOBAR")) | .[] .value' | tee /dev/stderr)
[ "${name}" = "foobar" ]

Expand All @@ -269,11 +293,11 @@ load _helpers
. | tee /dev/stderr |
yq -r '.spec.containers[0].env' | tee /dev/stderr)

local name=$(echo $object |
local name=$(echo "$object" |
yq -r 'map(select(.name=="FOO")) | .[] .value' | tee /dev/stderr)
[ "${name}" = "bar" ]

local name=$(echo $object |
local name=$(echo "$object" |
yq -r 'map(select(.name=="FOOBAR")) | .[] .value' | tee /dev/stderr)
[ "${name}" = "foobar" ]
}