From a54bdd00d592a2f3dfba2ec0427a3c1dc959b241 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Thu, 10 Aug 2023 17:48:25 -0300 Subject: [PATCH] tests: exec_host() now gets the node name The exec_host() simply fails on cluster with multi-nodes because `kubectl get node -o name" will return a list o names. Moreover, it will return control nodes names which usually don't have kata installed. Fixes #7619 Signed-off-by: Wainer dos Santos Moschetta (cherry picked from commit 3a00fc910122b024ef7e5775ec2793976ad56102) --- tests/integration/kubernetes/tests_common.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/integration/kubernetes/tests_common.sh b/tests/integration/kubernetes/tests_common.sh index 079080338a..3c8876e135 100644 --- a/tests/integration/kubernetes/tests_common.sh +++ b/tests/integration/kubernetes/tests_common.sh @@ -47,10 +47,14 @@ get_one_kata_node() { } # Runs a command in the host filesystem. +# +# Parameters: +# $1 - the node name +# exec_host() { - node="$(kubectl get node -o name)" + node="$1" # `kubectl debug` always returns 0, so we hack it to return the right exit code. - command="$@" + command="${@:2}" command+='; echo -en \\n$?' # We're trailing the `\r` here due to: https://github.com/kata-containers/kata-containers/issues/8051 # tl;dr: When testing with CRI-O we're facing the foillowing error: @@ -61,7 +65,7 @@ exec_host() { # [bats-exec-test:38] INFO: k8s configured to use runtimeclass # bash: line 1: $'\r': command not found # ``` - output="$(kubectl debug -qit "${node}" --image=alpine:latest -- chroot /host bash -c "${command}" | tr -d '\r')" + output="$(kubectl debug -qit "node/${node}" --image=alpine:latest -- chroot /host bash -c "${command}" | tr -d '\r')" kubectl get pods -o name | grep node-debugger | xargs kubectl delete > /dev/null exit_code="$(echo "${output}" | tail -1)" echo "$(echo "${output}" | head -n -1)"