From e8d1feb25f94b5c4c5d66be823e17f745cc498fb Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Wed, 25 Sep 2024 12:01:34 +0200 Subject: [PATCH] tests: Validate node name for exec_host() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current `exec_host()` accepts a given node name and creates a node debugger pod, even if the name is invalid. This could result in the creation of an unnecessary pending pod (since we are using nodeAffinity; if the given name does not match any actual node names, the pod won’t be scheduled), which wastes resources. This commit introduces validation for the node name to prevent this situation. Signed-off-by: Hyounggyu Choi --- tests/integration/kubernetes/lib.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/kubernetes/lib.sh b/tests/integration/kubernetes/lib.sh index 56713e950b..9c2297f0f5 100644 --- a/tests/integration/kubernetes/lib.sh +++ b/tests/integration/kubernetes/lib.sh @@ -71,6 +71,10 @@ k8s_create_pod() { # exec_host() { local node="$1" + # Validate the node + if ! kubectl get node "${node}" > /dev/null 2>&1; then + die "A given node ${node} is not valid" + fi # `kubectl debug` always returns 0, so we hack it to return the right exit code. local command="${@:2}" # Make 7 character hash from the node name