2018-08-18 05:08:03 +00:00
|
|
|
# name_prefix returns the prefix of the resources within Kubernetes.
|
|
|
|
name_prefix() {
|
2018-11-28 17:43:24 +00:00
|
|
|
printf "vault"
|
2018-08-18 05:08:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
# chart_dir returns the directory for the chart
|
|
|
|
chart_dir() {
|
|
|
|
echo ${BATS_TEST_DIRNAME}/../..
|
|
|
|
}
|
|
|
|
|
2018-11-28 17:43:24 +00:00
|
|
|
# helm_install installs the vault chart. This will source overridable
|
2018-08-21 17:25:37 +00:00
|
|
|
# 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() {
|
2018-08-21 17:25:37 +00:00
|
|
|
local values="${BATS_TEST_DIRNAME}/values.yaml"
|
|
|
|
if [ ! -f "${values}" ]; then
|
|
|
|
touch $values
|
|
|
|
fi
|
|
|
|
|
|
|
|
helm install -f ${values} \
|
2018-11-28 17:43:24 +00:00
|
|
|
--name vault \
|
2018-09-03 19:59:36 +00:00
|
|
|
${BATS_TEST_DIRNAME}/../..
|
2018-08-18 05:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 22:40:37 +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} \
|
2018-11-30 22:01:25 +00:00
|
|
|
--name vault \
|
|
|
|
--set 'server.enabled=false' \
|
|
|
|
--set 'serverHA.enabled=true' \
|
2018-11-28 22:40:37 +00:00
|
|
|
${BATS_TEST_DIRNAME}/../..
|
2018-08-18 05:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 22:54:03 +00:00
|
|
|
# wait for consul to be running
|
|
|
|
wait_for_running_consul() {
|
|
|
|
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.
|
2018-11-30 22:01:25 +00:00
|
|
|
kubectl get pods -l component=client -o json | \
|
|
|
|
jq -r '.items[0] | select(
|
2018-11-28 22:54:03 +00:00
|
|
|
.status.phase == "Running" and
|
|
|
|
([ .status.conditions[] | select(.type == "Ready" and .status == "True") ] | length) == 1
|
2018-11-30 22:01:25 +00:00
|
|
|
) | .metadata.name'
|
2018-11-28 22:54:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
for i in $(seq 60); do
|
2018-11-28 22:54:03 +00:00
|
|
|
if [ -n "$(check ${POD_NAME})" ]; then
|
2018-11-30 22:01:25 +00:00
|
|
|
echo "consul clients are ready."
|
2018-11-28 22:54:03 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Waiting for ${POD_NAME} to be ready..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
2018-11-30 22:01:25 +00:00
|
|
|
echo "consul clients never became ready."
|
2018-11-28 22:54:03 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2018-08-18 05:08:03 +00:00
|
|
|
# wait for a pod to be ready
|
2018-11-28 17:43:24 +00:00
|
|
|
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
|
2018-11-28 17:43:24 +00:00
|
|
|
([ .status.conditions[] | select(.type == "Ready" and .status == "False") ] | length) == 1
|
2018-08-18 05:08:03 +00:00
|
|
|
) | .metadata.namespace + "/" + .metadata.name'
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
for i in $(seq 60); do
|
|
|
|
if [ -n "$(check ${POD_NAME})" ]; then
|
|
|
|
echo "${POD_NAME} is ready."
|
2019-12-19 15:57:51 +00:00
|
|
|
sleep 5
|
2019-07-31 18:26:12 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Waiting for ${POD_NAME} to be ready..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "${POD_NAME} never became ready."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_ready() {
|
|
|
|
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 == "True") ] | length) == 1
|
|
|
|
) | .metadata.namespace + "/" + .metadata.name'
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in $(seq 60); do
|
2018-08-18 05:08:03 +00:00
|
|
|
if [ -n "$(check ${POD_NAME})" ]; then
|
|
|
|
echo "${POD_NAME} is ready."
|
2019-12-19 15:57:51 +00:00
|
|
|
sleep 5
|
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
|
|
|
|
}
|
2019-12-19 15:57:51 +00:00
|
|
|
|
|
|
|
wait_for_complete_job() {
|
|
|
|
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 job $1 -o json | \
|
|
|
|
jq -r 'select(
|
|
|
|
.status.succeeded == 1
|
|
|
|
) | .metadata.namespace + "/" + .metadata.name'
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in $(seq 60); do
|
|
|
|
if [ -n "$(check ${POD_NAME})" ]; then
|
|
|
|
echo "${POD_NAME} is complete."
|
|
|
|
sleep 5
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Waiting for ${POD_NAME} to be complete..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "${POD_NAME} never completed."
|
|
|
|
exit 1
|
|
|
|
}
|