k3s/scripts/sonobuoy

82 lines
1.9 KiB
Plaintext
Raw Normal View History

2019-04-29 20:54:51 +00:00
#!/bin/bash
set -xe
cd $(dirname $0)/..
2019-11-11 22:18:16 +00:00
. ./scripts/test-helpers
2019-04-29 20:54:51 +00:00
if [ -z "${K3S_IMAGE}" ]; then
2019-10-27 01:22:44 +00:00
echo 'K3S_IMAGE environment variable should be defined'
2019-04-29 20:54:51 +00:00
exit 1
fi
# ---
2019-07-04 15:07:26 +00:00
cleanup() {
exit_status=$?
set +e
2019-10-27 01:22:44 +00:00
echo 'Cleaning up'
2019-10-14 21:27:39 +00:00
trap - EXIT
[ -n "$SONOBUOY_PID" ] && kill $SONOBUOY_PID 2>/dev/null
2019-07-26 22:10:39 +00:00
if [ "${exit_status}" -ne "0" ]; then
2019-11-11 22:18:16 +00:00
dump-logs
2019-07-26 22:10:39 +00:00
fi
2019-07-04 15:07:26 +00:00
docker rm -f ${CONTAINERS} 2>/dev/null
rm ${KUBECONFIG}
exit ${exit_status}
}
trap cleanup EXIT
# ---
K3S_PORT=$(timeout --foreground 5s bash -c get-port)
OUTPUT=$(pwd)/sonobuoy-output/${K3S_PORT}
2019-07-28 00:01:10 +00:00
LOGS=$(pwd)/logs/$$
2019-07-04 15:07:26 +00:00
E2E="${OUTPUT}/e2e"
2019-10-27 01:22:44 +00:00
E2E_LOG='plugins/e2e/results/global/e2e.log'
2019-07-04 15:07:26 +00:00
RESULTS="${E2E}/${E2E_LOG}"
SECRET=random-$((100000 + RANDOM % 999999))
2019-11-11 22:18:16 +00:00
export K3S_AGENT=k3s-agent-${K3S_PORT}
export K3S_SERVER=k3s-server-${K3S_PORT}
2019-07-04 15:07:26 +00:00
export CONTAINERS="${K3S_SERVER} ${K3S_AGENT}"
export KUBECONFIG=${OUTPUT}/kubeconfig.yaml
2019-10-14 21:27:39 +00:00
mkdir -p ${OUTPUT}
2019-07-04 15:07:26 +00:00
# ---
docker run -d --name ${K3S_SERVER} --privileged \
-p 127.0.0.1:${K3S_PORT}:${K3S_PORT} \
-e K3S_CLUSTER_SECRET=${SECRET} \
2019-11-12 08:20:10 +00:00
-e K3S_DEBUG=true \
2019-07-04 15:07:26 +00:00
${K3S_IMAGE} server --no-deploy=traefik --https-listen-port=${K3S_PORT}
K3S_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${K3S_SERVER})
echo "Started ${K3S_SERVER} @ ${K3S_IP}:${K3S_PORT}"
timeout --foreground 1m bash -c wait-for-kubeconfig
verify-valid-versions ${K3S_SERVER}
# ---
2019-07-04 15:07:26 +00:00
docker run -d --name ${K3S_AGENT} --privileged \
-e K3S_CLUSTER_SECRET=${SECRET} \
-e K3S_URL=https://${K3S_IP}:${K3S_PORT} \
${K3S_IMAGE} agent
echo "Started ${K3S_AGENT}"
# ---
2019-10-27 01:22:44 +00:00
timeout --foreground 1m bash -c 'wait-for-nodes 2'
2019-11-09 16:06:03 +00:00
timeout --foreground 3m bash -c 'wait-for-services coredns local-path-provisioner metrics-server'
2019-07-04 15:07:26 +00:00
2019-10-27 01:22:44 +00:00
if [ "$ARCH" = 'arm' ]; then
echo "Aborting sonobuoy tests, images not available for $ARCH"
exit 0
fi
2019-10-27 01:22:44 +00:00
echo 'Starting sonobuoy tests'
2019-10-14 21:27:39 +00:00
sonobuoy-test "${@}"