From 448c808cf38fa6920fd4b7f85bf6759668a155fa Mon Sep 17 00:00:00 2001 From: Mohammad Issa Date: Tue, 13 Dec 2022 20:42:45 +0000 Subject: [PATCH] k8s-cni-cache-cleanup: use ActiveEnterTimestamp The script in k8s-cni-cache-cleanup is failing to run because 'WatchdogTimestamp' no longer exists. Instead we use another timestamp, namely ActiveEnterTimestamp. Test Plan: PASS: Lock and unlock the controller and verify that the cleanup works properly PASS: Launch pods using extra cni interfaces and make sure they work properly using specific test cases Closes-Bug: 1999570 Signed-off-by: Mohammad Issa Change-Id: I36881a2802d150d7b36d204bf45511752d7f8401 --- .../centos/files/k8s-cni-cache-cleanup | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/kubernetes/k8s-cni-cache-cleanup/centos/files/k8s-cni-cache-cleanup b/kubernetes/k8s-cni-cache-cleanup/centos/files/k8s-cni-cache-cleanup index e1435228d..0e438a642 100644 --- a/kubernetes/k8s-cni-cache-cleanup/centos/files/k8s-cni-cache-cleanup +++ b/kubernetes/k8s-cni-cache-cleanup/centos/files/k8s-cni-cache-cleanup @@ -130,15 +130,29 @@ function check_cache_file_age { function kubelet_uptime { local SECONDSPERMINUTE=60 - kubelet_uptime=$(systemctl show kubelet --property WatchdogTimestamp | awk -F= '{print $2}') - [[ -n ${kubelet_uptime} ]] - if [ ${?} -ne 0 ]; then - ERROR "Failed to get kubelet uptime." - minutes=0 + # Check if the kubelet service is active + kubelet_status=$(systemctl is-active kubelet) + if [ "${kubelet_status}" = "active" ]; then + kubelet_ts_property=$(systemctl show kubelet --property ActiveEnterTimestamp) + 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 - uptime=$(date --date="${kubelet_uptime}" +%s) - now=$(date +%s) - minutes=$(((${now}-${uptime})/${SECONDSPERMINUTE})) + # Log an error message if the kubelet service is not active + ERROR "The kubelet service is not active." + minutes=0 fi echo ${minutes}