Skip to content

Commit

Permalink
Merge pull request #13952 from stevekuznetsov/skuznets/cluster-up-logs
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Apr 29, 2017
2 parents fed098c + dacfb85 commit 40c6e2e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
46 changes: 38 additions & 8 deletions hack/lib/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function os::cleanup::dump_etcd() {
os::util::curl_etcd "/v2/keys/?recursive=true" > "${ARTIFACT_DIR}/etcd_dump.json"
}

# os::cleanup::containers operates on k8s containers to stop the containers
# os::cleanup::containers operates on our containers to stop the containers
# and optionally remove the containers and any volumes they had attached.
#
# Globals:
Expand All @@ -31,8 +31,8 @@ function os::cleanup::containers() {
return
fi

os::log::info "Stopping k8s docker containers"
for id in $( os::cleanup::internal::list_k8s_containers ); do
os::log::info "Stopping docker containers"
for id in $( os::cleanup::internal::list_our_containers ); do
os::log::debug "Stopping ${id}"
docker stop "${id}" >/dev/null
done
Expand All @@ -41,8 +41,8 @@ function os::cleanup::containers() {
return
fi

os::log::info "Removing k8s docker containers"
for id in $( os::cleanup::internal::list_k8s_containers ); do
os::log::info "Removing docker containers"
for id in $( os::cleanup::internal::list_our_containers ); do
os::log::debug "Removing ${id}"
docker stop "${id}" >/dev/null
done
Expand All @@ -68,14 +68,29 @@ function os::cleanup::dump_container_logs() {
mkdir -p "${container_log_dir}"

os::log::info "Dumping container logs to ${container_log_dir}"
for id in $( os::cleanup::internal::list_k8s_containers ); do
for id in $( os::cleanup::internal::list_our_containers ); do
local name; name="$( docker inspect --format '{{ .Name }}' "${id}" )"
os::log::debug "Dumping logs for ${id} to ${name}.log"
docker logs "${id}" >"${container_log_dir}/${name}.log" 2>&1
done
}
readonly -f os::cleanup::dump_container_logs

# os::cleanup::internal::list_our_containers returns a space-delimited list of
# docker containers that belonged to some part of the Origin deployment.
#
# Globals:
# None
# Arguments:
# None
# Returns:
# None
function os::cleanup::internal::list_our_containers() {
os::cleanup::internal::list_containers '^/origin$'
os::cleanup::internal::list_k8s_containers
}
readonly -f os::cleanup::internal::list_our_containers

# os::cleanup::internal::list_k8s_containers returns a space-delimited list of
# docker containers that belonged to k8s.
#
Expand All @@ -86,18 +101,33 @@ readonly -f os::cleanup::dump_container_logs
# Returns:
# None
function os::cleanup::internal::list_k8s_containers() {
os::cleanup::internal::list_containers '^/k8s_.*'
}
readonly -f os::cleanup::internal::list_k8s_containers

# os::cleanup::internal::list_containers returns a space-delimited list of
# docker containers that match a name regex.
#
# Globals:
# None
# Arguments:
# 1 - regex to match on the name
# Returns:
# None
function os::cleanup::internal::list_containers() {
local regex="$1"
local ids;
for short_id in $( docker ps -aq ); do
local id; id="$( docker inspect --format '{{ .Id }}' "${short_id}" )"
local name; name="$( docker inspect --format '{{ .Name }}' "${id}" )"
if [[ "${name}" =~ ^/k8s_.* ]]; then
if [[ "${name}" =~ ${regex} ]]; then
ids+=( "${id}" )
fi
done

echo "${ids[*]:+"${ids[*]}"}"
}
readonly -f os::cleanup::internal::list_k8s_containers
readonly -f os::cleanup::internal::list_containers

# os::cleanup::tmpdir performs cleanup of temp directories as a precondition for running a test. It tries to
# clean up mounts in the temp directories.
Expand Down
14 changes: 0 additions & 14 deletions hack/test-end-to-end-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,9 @@ function cleanup()
os::cleanup::dump_etcd

if [[ -z "${SKIP_TEARDOWN-}" ]]; then
os::log::info "remove the openshift container"
docker stop origin
docker rm origin

os::cleanup::containers
set -u
fi

journalctl --unit docker.service --since -15minutes > "${LOG_DIR}/docker.log"

truncate_large_logs
os::test::junit::generate_oscmd_report
set -e
Expand All @@ -63,13 +56,6 @@ trap "cleanup" EXIT INT TERM

os::log::system::start

out=$(
set +e
docker stop origin 2>&1
docker rm origin 2>&1
set -e
)

# Setup
os::log::info "openshift version: `openshift version`"
os::log::info "oc version: `oc version`"
Expand Down
5 changes: 0 additions & 5 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ function cleanup_openshift() {
set -u
fi

if grep -q 'no Docker socket found' "${LOG_DIR}/openshift.log" && command -v journalctl >/dev/null 2>&1; then
# the Docker daemon crashed, we need the logs
journalctl --unit docker.service --since -4hours > "${LOG_DIR}/docker.log"
fi

truncate_large_logs

os::log::info "Cleanup complete"
Expand Down

0 comments on commit 40c6e2e

Please sign in to comment.