From ab27cf3bfd32bca9dd071d319f557d5df7ee50a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Fri, 8 Dec 2023 15:13:26 +0100 Subject: [PATCH] tests/e2e: Wait for no restarts after deployment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukáš Doktor --- tests/e2e/operator.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/e2e/operator.sh b/tests/e2e/operator.sh index ee3e7391..864cbbb3 100755 --- a/tests/e2e/operator.sh +++ b/tests/e2e/operator.sh @@ -258,6 +258,40 @@ uninstall_operator() { fi } +# Wait for no restarts in 3x20s (15s is the liveness probe) +# +wait_for_stabilization() { + declare -A restart_counts + iteration=0 + count=0 + while true; do + change=0 + pod_info=$(kubectl get pods -n confidential-containers-system -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{range .status.containerStatuses[*]}{.name}{" "}{.restartCount}{"\n"}{end}{end}') + + while read -r pod container restart_count; do + if [ "${restart_counts[$pod-$container]--1}" != "$restart_count" ]; then + echo "DEBUG: Pod: $pod, Container: $container, Restart count: $restart_count" + restart_counts["$pod-$container"]=$restart_count + change=1 + fi + done <<< "$pod_info" + + [ $change -eq 0 ] && ((iteration+=1)) + + if [ $iteration -gt 3 ]; then + echo "INFO: No new restarts in 3x20s, proceeding..." + break + elif [ $count -gt 20 ]; then + echo "ERROR: Pods are still restarting after 20x20s, bail out!" + return 1 + fi + + ((count+=1)) + sleep 20 + done +} + + usage() { cat <<-EOF Utility to build/install/uninstall the operator. @@ -281,6 +315,7 @@ main() { install_operator build_pre_install_img install_ccruntime + wait_for_stabilization else case $1 in -h|--help) usage && exit 0;;