From e874c8fa2e62a2c1b641a65bc549e73e39134416 Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Tue, 9 Jul 2024 22:27:44 +0800 Subject: [PATCH] tests: Delete test scripts forcely Delete test scripts forcely in `Delete kata-deploy` step before deleting all kata pods. Fixes: #9980 Signed-off-by: ChengyuZhu6 --- tests/gha-run-k8s-common.sh | 11 +++++++++++ tests/integration/kubernetes/gha-run.sh | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/tests/gha-run-k8s-common.sh b/tests/gha-run-k8s-common.sh index aad9e3d65a..cb9535e145 100644 --- a/tests/gha-run-k8s-common.sh +++ b/tests/gha-run-k8s-common.sh @@ -364,3 +364,14 @@ function delete_test_cluster_namespace() { set_default_cluster_namespace kubectl delete namespace "${TEST_CLUSTER_NAMESPACE}" } + +function delete_test_runners(){ + echo "Delete test scripts" + local scripts_names=( "run_kubernetes_tests.sh" "bats" ) + for script_name in "${scripts_names[@]}"; do + pids=$(pgrep -f ${script_name}) + if [ -n "$pids" ]; then + echo "$pids" | xargs sudo kill -SIGTERM >/dev/null 2>&1 || true + fi + done +} diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index 3cc6441d17..edc0e3ea9d 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -450,6 +450,10 @@ function cleanup() { return fi + # In case of canceling workflow manually, 'run_kubernetes_tests.sh' continues running and triggers new tests, + # resulting in the CI being in an unexpected state. So we need kill all running test scripts before cleaning up the node. + # See issue https://github.com/kata-containers/kata-containers/issues/9980 + delete_test_runners || true # Switch back to the default namespace and delete the tests one delete_test_cluster_namespace || true