mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Automatically clean up KUBE_TEMP
kube::util:ensure-temp-dir claims that it will automatically clean it up. But it obviously doesn't. Since we cannot add multiple trap in bash add a function that lets us trap and clean up KUBE_TEMP even if someone already set a trap.
This commit is contained in:
parent
bafa7627db
commit
9cf7bb6b4f
@ -48,6 +48,36 @@ kube::util::wait_for_url() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Example: kube::util::trap_add 'echo "in trap DEBUG"' DEBUG
|
||||||
|
# See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
|
||||||
|
kube::util::trap_add() {
|
||||||
|
local trap_add_cmd
|
||||||
|
trap_add_cmd=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
for trap_add_name in "$@"; do
|
||||||
|
local existing_cmd
|
||||||
|
local new_cmd
|
||||||
|
|
||||||
|
# Grab the currently defined trap commands for this trap
|
||||||
|
existing_cmd=`trap -p "${trap_add_name}" | awk -F"'" '{print $2}'`
|
||||||
|
|
||||||
|
if [[ -z "${existing_cmd}" ]]; then
|
||||||
|
new_cmd="${trap_add_cmd}"
|
||||||
|
else
|
||||||
|
new_cmd="${existing_cmd};${trap_add_cmd}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Assign the test
|
||||||
|
trap "${new_cmd}" "${trap_add_name}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Opposite of kube::util::ensure-temp-dir()
|
||||||
|
kube::util::cleanup-temp-dir() {
|
||||||
|
rm -rf "${KUBE_TEMP}"
|
||||||
|
}
|
||||||
|
|
||||||
# Create a temp dir that'll be deleted at the end of this bash session.
|
# Create a temp dir that'll be deleted at the end of this bash session.
|
||||||
#
|
#
|
||||||
# Vars set:
|
# Vars set:
|
||||||
@ -55,6 +85,7 @@ kube::util::wait_for_url() {
|
|||||||
kube::util::ensure-temp-dir() {
|
kube::util::ensure-temp-dir() {
|
||||||
if [[ -z ${KUBE_TEMP-} ]]; then
|
if [[ -z ${KUBE_TEMP-} ]]; then
|
||||||
KUBE_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t kubernetes.XXXXXX)
|
KUBE_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t kubernetes.XXXXXX)
|
||||||
|
kube::util::trap_add kube::util::cleanup-temp-dir EXIT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,7 @@ function check-curl-proxy-code()
|
|||||||
echo "For address ${full_address}, got ${status} but wanted ${desired}"
|
echo "For address ${full_address}, got ${status} but wanted ${desired}"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
kube::util::trap_add cleanup EXIT SIGINT
|
||||||
trap cleanup EXIT SIGINT
|
|
||||||
|
|
||||||
kube::util::ensure-temp-dir
|
kube::util::ensure-temp-dir
|
||||||
kube::etcd::start
|
kube::etcd::start
|
||||||
|
Loading…
Reference in New Issue
Block a user