From f7d902424974998ad46cbf6d3b6b3e472aed3a24 Mon Sep 17 00:00:00 2001 From: Rophy Tsai Date: Fri, 3 Apr 2026 07:34:18 +0000 Subject: [PATCH] tests: strip \r from kubectl exec output for TTY containers The busybox-pod.yaml test fixture sets tty: true on the second container. When a container has a TTY, kubectl exec may return \r\n line endings. The invisible \r causes string comparisons to fail: container_name=$(kubectl exec ... -- env | grep CONTAINER_NAME) [ "$container_name" == "CONTAINER_NAME=second-test-container" ] This comparison fails because $container_name contains a trailing \r character. Fix by piping through tr -d '\r' after grep. This is harmless when \r is absent and fixes the mismatch when present. Fixes: #9136 Signed-off-by: Rophy Tsai --- tests/integration/kubernetes/k8s-exec.bats | 4 ++-- tests/integration/kubernetes/k8s-pid-ns.bats | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/integration/kubernetes/k8s-exec.bats b/tests/integration/kubernetes/k8s-exec.bats index b089c262fa..d984f03671 100644 --- a/tests/integration/kubernetes/k8s-exec.bats +++ b/tests/integration/kubernetes/k8s-exec.bats @@ -69,11 +69,11 @@ EOF" ## Cases for target container ### First container - container_name=$(kubectl exec $pod_name -c $first_container_name -- $env_command | grep CONTAINER_NAME) + container_name=$(kubectl exec $pod_name -c $first_container_name -- $env_command | grep CONTAINER_NAME | tr -d '\r') [ "$container_name" == "CONTAINER_NAME=$first_container_name" ] ### Second container - container_name=$(kubectl exec $pod_name -c $second_container_name -- $env_command | grep CONTAINER_NAME) + container_name=$(kubectl exec $pod_name -c $second_container_name -- $env_command | grep CONTAINER_NAME | tr -d '\r') [ "$container_name" == "CONTAINER_NAME=$second_container_name" ] } diff --git a/tests/integration/kubernetes/k8s-pid-ns.bats b/tests/integration/kubernetes/k8s-pid-ns.bats index 8cfada5247..774e4060b7 100644 --- a/tests/integration/kubernetes/k8s-pid-ns.bats +++ b/tests/integration/kubernetes/k8s-pid-ns.bats @@ -35,15 +35,16 @@ setup() { kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name # Check PID from first container + # Strip \r — containers with tty: true return \r\n line endings first_pid_container=$(kubectl exec $pod_name -c $first_container_name \ - -- $ps_command | grep "/pause") + -- $ps_command | grep "/pause" | tr -d '\r') # Verify that is not empty check_first_pid=$(echo $first_pid_container | wc -l) [ "$check_first_pid" == "1" ] # Check PID from second container second_pid_container=$(kubectl exec $pod_name -c $second_container_name \ - -- $ps_command | grep "/pause") + -- $ps_command | grep "/pause" | tr -d '\r') # Verify that is not empty check_second_pid=$(echo $second_pid_container | wc -l) [ "$check_second_pid" == "1" ]