Skip to content

Commit

Permalink
Make dockerized-e2e-runner.sh kill the container on timeout.
Browse files Browse the repository at this point in the history
This was tested manually with the small script:

    #!/bin/bash
    # test with "timeout -k4 2 ./leak-test.sh"
    # observe that the trap properly cleans up the container.

    CONTAINER_NAME="leak-$$"

    echo "container: $CONTAINER_NAME"
    trap "docker kill ${CONTAINER_NAME}" EXIT

    docker run --rm --name="${CONTAINER_NAME}" ubuntu sleep 600

    trap '' EXIT

This should fix flakes associated with leaked containers:
kubernetes/kubernetes#30962 and kubernetes/kubernetes#31213
  • Loading branch information
Ryan Hitchman committed Aug 31, 2016
1 parent 5713900 commit c7d697b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion jenkins/dockerized-e2e-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ if [[ "${KUBE_RUN_FROM_OUTPUT:-}" =~ ^[yY]$ ]]; then
)
fi

# Timeouts can leak the container, causing weird issues where the job keeps
# running and *deletes resources* that the next job is using.
# Give the container a unique name, and make bash kill it on EXIT,
# which will happen during a timeout.
CONTAINER_NAME="${JOB_NAME}-${BUILD_NUMBER}"
trap "docker kill ${CONTAINER_NAME}" EXIT

echo "Starting..."
docker run --rm=true -i \
docker run --rm -i \
--name="${CONTAINER_NAME}"
-v "${WORKSPACE}/_artifacts":/workspace/_artifacts \
-v /etc/localtime:/etc/localtime:ro \
${JENKINS_GCE_SSH_PRIVATE_KEY_FILE:+-v "${JENKINS_GCE_SSH_PRIVATE_KEY_FILE}:/workspace/.ssh/google_compute_engine:ro"} \
Expand All @@ -76,3 +84,5 @@ docker run --rm=true -i \
${GOOGLE_APPLICATION_CREDENTIALS:+-e "GOOGLE_APPLICATION_CREDENTIALS=/service-account.json"} \
"${docker_extra_args[@]:+${docker_extra_args[@]}}" \
"gcr.io/google-containers/kubekins-e2e:${KUBEKINS_E2E_IMAGE_TAG}"

trap '' EXIT # container exited normally

0 comments on commit c7d697b

Please sign in to comment.