From 518aac2b78f9aff999cfecf59615f0cabeadbd42 Mon Sep 17 00:00:00 2001 From: Erik Wilson Date: Mon, 1 Jul 2019 15:50:16 -0700 Subject: [PATCH] Clean up sonobuoy cleanup --- scripts/sonobuoy | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/sonobuoy b/scripts/sonobuoy index a9bb458142..1a291af1dd 100755 --- a/scripts/sonobuoy +++ b/scripts/sonobuoy @@ -32,6 +32,7 @@ mkdir -p ${OUTPUT} SECRET=random-$((100000 + RANDOM % 999999)) export K3S_AGENT=sonobuoy-k3s-agent-${K3S_PORT} export K3S_SERVER=sonobuoy-k3s-server-${K3S_PORT} +export CONTAINERS="${K3S_SERVER} ${K3S_AGENT}" export KUBECONFIG=${OUTPUT}/kubeconfig.yaml # --- @@ -40,19 +41,24 @@ cleanup() { exit_status=$? set +e echo "Cleaning up" - for container in ${K3S_SERVER} ${K3S_AGENT}; do + docker rm -f ${CONTAINERS} 2>/dev/null + rm ${KUBECONFIG} + exit ${exit_status} +} +trap cleanup EXIT + +# --- + +dump-logs() { + for container in ${CONTAINERS}; do docker cp ${container}:/var/lib/rancher/k3s/agent/containerd/containerd.log ${OUTPUT}/${container}-containerd.log docker logs ${container} >${OUTPUT}/${container}.log 2>&1 - docker rm -f ${container} 2>/dev/null if [ ${exit_status} -ne 0 ]; then cat ${OUTPUT}/${container}-containerd.log cat ${OUTPUT}/${container}.log fi done - rm ${KUBECONFIG} - exit ${exit_status} } -trap cleanup EXIT # --- @@ -146,7 +152,10 @@ sonobuoy retrieve ${OUTPUT} cd ${OUTPUT} tar xzf *_sonobuoy_*.tar.gz results="./plugins/e2e/results/e2e.log" - [ -s ${results} ] || exit 1 + [ -s ${results} ] || { + dump-logs + exit 1 + } tail -20 ${results} exit_code=0