openbao-helm/test/acceptance/_helpers.bash

68 lines
2.1 KiB
Bash
Raw Normal View History

2018-08-18 05:08:03 +00:00
# name_prefix returns the prefix of the resources within Kubernetes.
name_prefix() {
printf "vault"
2018-08-18 05:08:03 +00:00
}
# helm_install installs the vault chart. This will source overridable
# values from the "values.yaml" file in this directory. This can be set
# by CI or other environments to do test-specific overrides. Note that its
# easily possible to break tests this way so be careful.
2018-08-18 05:08:03 +00:00
helm_install() {
local values="${BATS_TEST_DIRNAME}/values.yaml"
if [ ! -f "${values}" ]; then
touch $values
fi
helm install -f ${values} \
--name vault \
2018-09-03 19:59:36 +00:00
${BATS_TEST_DIRNAME}/../..
2018-08-18 05:08:03 +00:00
}
# helm_install_ha installs the vault chart using HA mode. This will source
# overridable values from the "values.yaml" file in this directory. This can be
# set by CI or other environments to do test-specific overrides. Note that its
# easily possible to break tests this way so be careful.
helm_install_ha() {
local values="${BATS_TEST_DIRNAME}/values.yaml"
if [ ! -f "${values}" ]; then
touch $values
fi
helm install -f ${values} \
--name vault \
--set 'sever.enabled=false' \
--set 'severHA.enabled=true' \
${BATS_TEST_DIRNAME}/../..
2018-08-18 05:08:03 +00:00
}
# wait for a pod to be ready
wait_for_running() {
2018-08-18 05:08:03 +00:00
POD_NAME=$1
check() {
# This requests the pod and checks whether the status is running
# and the ready state is true. If so, it outputs the name. Otherwise
# it outputs empty. Therefore, to check for success, check for nonzero
# string length.
kubectl get pods $1 -o json | \
jq -r 'select(
.status.phase == "Running" and
([ .status.conditions[] | select(.type == "Ready" and .status == "False") ] | length) == 1
2018-08-18 05:08:03 +00:00
) | .metadata.namespace + "/" + .metadata.name'
}
for i in $(seq 30); do
if [ -n "$(check ${POD_NAME})" ]; then
echo "${POD_NAME} is ready."
sleep 2
2018-08-18 05:08:03 +00:00
return
fi
echo "Waiting for ${POD_NAME} to be ready..."
sleep 2
done
echo "${POD_NAME} never became ready."
exit 1
}