mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Add warning function that includes timestamp
Knowing when a process has terminated is helpful when looking through log files (especially very large ones). This also refactors the terminal coloring function to be used with custom prefix and colors. warning_log outputs red text in the current e2e inspired format: W0628 16:58:26]: this is a test
This commit is contained in:
parent
c94efcea1d
commit
ae271b4db0
@ -399,12 +399,12 @@ cleanup()
|
|||||||
# a process dies unexpectedly.
|
# a process dies unexpectedly.
|
||||||
function healthcheck {
|
function healthcheck {
|
||||||
if [[ -n "${APISERVER_PID-}" ]] && ! sudo kill -0 ${APISERVER_PID} 2>/dev/null; then
|
if [[ -n "${APISERVER_PID-}" ]] && ! sudo kill -0 ${APISERVER_PID} 2>/dev/null; then
|
||||||
warning "API server terminated unexpectedly, see ${APISERVER_LOG}"
|
warning_log "API server terminated unexpectedly, see ${APISERVER_LOG}"
|
||||||
APISERVER_PID=
|
APISERVER_PID=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${CTLRMGR_PID-}" ]] && ! sudo kill -0 ${CTLRMGR_PID} 2>/dev/null; then
|
if [[ -n "${CTLRMGR_PID-}" ]] && ! sudo kill -0 ${CTLRMGR_PID} 2>/dev/null; then
|
||||||
warning "kube-controller-manager terminated unexpectedly, see ${CTLRMGR_LOG}"
|
warning_log "kube-controller-manager terminated unexpectedly, see ${CTLRMGR_LOG}"
|
||||||
CTLRMGR_PID=
|
CTLRMGR_PID=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -412,32 +412,37 @@ function healthcheck {
|
|||||||
# TODO (https://github.com/kubernetes/kubernetes/issues/62474): check health also in this case
|
# TODO (https://github.com/kubernetes/kubernetes/issues/62474): check health also in this case
|
||||||
:
|
:
|
||||||
elif [[ -n "${KUBELET_PID-}" ]] && ! sudo kill -0 ${KUBELET_PID} 2>/dev/null; then
|
elif [[ -n "${KUBELET_PID-}" ]] && ! sudo kill -0 ${KUBELET_PID} 2>/dev/null; then
|
||||||
warning "kubelet terminated unexpectedly, see ${KUBELET_LOG}"
|
warning_log "kubelet terminated unexpectedly, see ${KUBELET_LOG}"
|
||||||
KUBELET_PID=
|
KUBELET_PID=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${PROXY_PID-}" ]] && ! sudo kill -0 ${PROXY_PID} 2>/dev/null; then
|
if [[ -n "${PROXY_PID-}" ]] && ! sudo kill -0 ${PROXY_PID} 2>/dev/null; then
|
||||||
warning "kube-proxy terminated unexpectedly, see ${PROXY_LOG}"
|
warning_log "kube-proxy terminated unexpectedly, see ${PROXY_LOG}"
|
||||||
PROXY_PID=
|
PROXY_PID=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${SCHEDULER_PID-}" ]] && ! sudo kill -0 ${SCHEDULER_PID} 2>/dev/null; then
|
if [[ -n "${SCHEDULER_PID-}" ]] && ! sudo kill -0 ${SCHEDULER_PID} 2>/dev/null; then
|
||||||
warning "scheduler terminated unexpectedly, see ${SCHEDULER_LOG}"
|
warning_log "scheduler terminated unexpectedly, see ${SCHEDULER_LOG}"
|
||||||
SCHEDULER_PID=
|
SCHEDULER_PID=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${ETCD_PID-}" ]] && ! sudo kill -0 ${ETCD_PID} 2>/dev/null; then
|
if [[ -n "${ETCD_PID-}" ]] && ! sudo kill -0 ${ETCD_PID} 2>/dev/null; then
|
||||||
warning "etcd terminated unexpectedly"
|
warning_log "etcd terminated unexpectedly"
|
||||||
ETCD_PID=
|
ETCD_PID=
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function warning {
|
function print_color {
|
||||||
message=$1
|
message=$1
|
||||||
|
prefix=${2:+$2: } # add colon only if defined
|
||||||
|
color=${3:-1} # default is red
|
||||||
|
echo -n $(tput bold)$(tput setaf ${color})
|
||||||
|
echo "${prefix}${message}"
|
||||||
|
echo -n $(tput sgr0)
|
||||||
|
}
|
||||||
|
|
||||||
echo $(tput bold)$(tput setaf 1)
|
function warning_log {
|
||||||
echo "WARNING: ${message}"
|
print_color "$1" "W$(date "+%m%d %H:%M:%S")]" 1
|
||||||
echo $(tput sgr0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_etcd {
|
function start_etcd {
|
||||||
@ -1071,14 +1076,14 @@ if [[ "${START_MODE}" != "nokubelet" ]]; then
|
|||||||
# Detect the OS name/arch and display appropriate error.
|
# Detect the OS name/arch and display appropriate error.
|
||||||
case "$(uname -s)" in
|
case "$(uname -s)" in
|
||||||
Darwin)
|
Darwin)
|
||||||
warning "kubelet is not currently supported in darwin, kubelet aborted."
|
print_color "kubelet is not currently supported in darwin, kubelet aborted."
|
||||||
KUBELET_LOG=""
|
KUBELET_LOG=""
|
||||||
;;
|
;;
|
||||||
Linux)
|
Linux)
|
||||||
start_kubelet
|
start_kubelet
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warning "Unsupported host OS. Must be Linux or Mac OS X, kubelet aborted."
|
print_color "Unsupported host OS. Must be Linux or Mac OS X, kubelet aborted."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user