Merge "k8s-cni-cache-cleanup: use ActiveEnterTimestamp"
This commit is contained in:
commit
b8fb4fb211
@ -130,15 +130,29 @@ function check_cache_file_age {
|
|||||||
function kubelet_uptime {
|
function kubelet_uptime {
|
||||||
local SECONDSPERMINUTE=60
|
local SECONDSPERMINUTE=60
|
||||||
|
|
||||||
kubelet_uptime=$(systemctl show kubelet --property WatchdogTimestamp | awk -F= '{print $2}')
|
# Check if the kubelet service is active
|
||||||
[[ -n ${kubelet_uptime} ]]
|
kubelet_status=$(systemctl is-active kubelet)
|
||||||
if [ ${?} -ne 0 ]; then
|
if [ "${kubelet_status}" = "active" ]; then
|
||||||
ERROR "Failed to get kubelet uptime."
|
kubelet_ts_property=$(systemctl show kubelet --property ActiveEnterTimestamp)
|
||||||
minutes=0
|
RC=${?}
|
||||||
|
if [ "${RC}" -eq 0 ]; then
|
||||||
|
kubelet_uptime=$( echo "${kubelet_ts_property}" | awk -F= '{print $2}' )
|
||||||
|
if [ -z "${kubelet_uptime}" ]; then
|
||||||
|
ERROR "Failed to get kubelet uptime, kubelet_uptime=${kubelet_uptime}"
|
||||||
|
minutes=0
|
||||||
|
else
|
||||||
|
uptime=$(date --date="${kubelet_uptime}" +%s)
|
||||||
|
now=$(date +%s)
|
||||||
|
minutes=$(((${now}-${uptime})/${SECONDSPERMINUTE}))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
ERROR "Failed to get kubelet uptime, RC=${RC}"
|
||||||
|
minutes=0
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
uptime=$(date --date="${kubelet_uptime}" +%s)
|
# Log an error message if the kubelet service is not active
|
||||||
now=$(date +%s)
|
ERROR "The kubelet service is not active."
|
||||||
minutes=$(((${now}-${uptime})/${SECONDSPERMINUTE}))
|
minutes=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ${minutes}
|
echo ${minutes}
|
||||||
|
Loading…
Reference in New Issue
Block a user