Created
May 4, 2017 05:16
-
-
Save ahawkins/f63ee3f99b237f9b0468035de184d688 to your computer and use it in GitHub Desktop.
Updated script/test-release for helm test run #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
main() { | |
local release="${1:-}" test_output pod | |
test_output="$(mktemp)" | |
if [ -z "${release}" ]; then | |
echo "USAGE: ${0} RELEASE" 1>&2 | |
return 1 | |
fi | |
kubectl delete pod \ | |
-l "release=${release},app=smoke-test" \ | |
-n "${KUBE_NAMESPACE}" \ | |
--context "${KUBE_CONTEXT}" &> /dev/null | |
# FIXME: This is a work around for https://github.com/kubernetes/helm/issues/2166 | |
set +e | |
helm test "${release}" --timeout 600 --kube-context "${KUBE_CONTEXT}" > "${test_output}" | |
set -e | |
if grep -qF 'PASSED' "${test_output}"; then | |
cat "${test_output}" | |
kubectl delete pod \ | |
-l "release=${release},app=smoke-test" \ | |
-n "${KUBE_NAMESPACE}" \ | |
--context "${KUBE_CONTEXT}" &> /dev/null | |
return 0 | |
else | |
echo "${release} test failed! Capturing logs and cleaning up" | |
echo | |
cat "${test_output}" | |
while read -r pod; do | |
echo "${pod} Logs:" | |
echo | |
kubectl logs "${pod}" -n "${KUBE_NAMESPACE}" --context "${KUBE_CONTEXT}" | |
kubectl delete pod "${pod}" -n "${KUBE_NAMESPACE}" --context "${KUBE_CONTEXT}" | |
echo | |
done < <(kubectl get pod \ | |
--show-all \ | |
-o "custom-columns=NAME:.metadata.name" \ | |
-l "release=${release},app=smoke-test" \ | |
-n "${KUBE_NAMESPACE}" \ | |
--context "${KUBE_CONTEXT}" \ | |
| tail -n +2) | |
echo | |
echo "${release} pod status" | |
kubectl get pod \ | |
--show-all \ | |
-o wide \ | |
-l "release=${release}" \ | |
-n "${KUBE_NAMESPACE}" \ | |
--context "${KUBE_CONTEXT}" | |
echo | |
echo "${release} non-running pod info" | |
echo | |
while read -r line; do | |
pod="$(echo "${line}" | cut -d ' ' -f 1)" | |
kubectl describe pod "${pod}" -n "${KUBE_NAMESPACE}" --context "${KUBE_CONTEXT}" | |
echo | |
echo | |
done < <(kubectl get pods \ | |
-l "release=${release}" \ | |
-o 'custom-columns=NAME:.metadata.name,STATUS:.status.phase' \ | |
-n "${KUBE_NAMESPACE}" \ | |
--context "${KUBE_CONTEXT}" \ | |
| tail -n +2 \ | |
| grep -vF 'Running' | |
) | |
return 1 | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment