diff --git a/tests/integration/kubernetes/k8s-debug-console.bats b/tests/integration/kubernetes/k8s-debug-console.bats new file mode 100644 index 0000000000..e037ab7be2 --- /dev/null +++ b/tests/integration/kubernetes/k8s-debug-console.bats @@ -0,0 +1,55 @@ +#!/usr/bin/env bats +# Copyright (c) 2025 Advanced Micro Devices, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/tests_common.sh" +load "${BATS_TEST_DIRNAME}/lib.sh" + +# For kata-runtime +export KATA_HOME="/opt/kata" +export KATA_RUNTIME="${KATA_HOME}/bin/kata-runtime" + +timeout=${timeout:-30} + +setup() { + if [[ "${K8S_TEST_HOST_TYPE}" != "baremetal" ]]; then + skip "Debug console only available from baremetal systems" + fi + + pod_name="busybox-base-pod" + get_pod_config_dir + yaml_file="${pod_config_dir}/pod-busybox-base.yaml" +} + +@test "Access and verify that the debug console is working" { + # Create pod + kubectl apply -f "${yaml_file}" + + # Check pod creation + kubectl wait --for=condition=Ready --timeout=${timeout} pod "${pod_name}" + + # Get sandbox ID + sandbox_id=$(get_kata_sandbox_id_by_pod_name "${pod_name}") + echo "Sandbox ID for pod [${pod_name}]: ${sandbox_id}" + + # Test debug console + local kata_agent_path=$(sudo "${KATA_RUNTIME}" exec "${sandbox_id}" which kata-agent) + if [[ ! "${kata_agent_path}" =~ "kata-agent" ]]; then + echo "ERROR: The debug console could not locate the kata-agent: ${kata_agent_path}" >&2 + return 1 + fi +} + +teardown() { + if [[ "${K8S_TEST_HOST_TYPE}" != "baremetal" ]]; then + skip "Debug console only available from baremetal systems" + fi + + # Debugging information + kubectl describe "pod/${pod_name}" + + kubectl delete pod "${pod_name}" +} diff --git a/tests/integration/kubernetes/lib.sh b/tests/integration/kubernetes/lib.sh index bfc4c3c3d9..521c36951a 100644 --- a/tests/integration/kubernetes/lib.sh +++ b/tests/integration/kubernetes/lib.sh @@ -372,3 +372,19 @@ get_node_kata_sandbox_id() { done echo $kata_sandbox_id } + +get_kata_sandbox_id_by_pod_name() { + local pod_name="${1}" + + # Get sandbox ID from crictl + local sandbox_id=$(sudo crictl inspectp --name "${pod_name}" | jq -r '.status.id') + + # Error handle + if [ -z "${sandbox_id}" ]; then + echo "ERROR: Could not determine sandbox ID for pod with name: ${pod_name}" >&2 + return 1 + fi + + # Return + echo "${sandbox_id}" +} diff --git a/tests/integration/kubernetes/run_kubernetes_tests.sh b/tests/integration/kubernetes/run_kubernetes_tests.sh index a62dcfe073..4c7326f6a5 100755 --- a/tests/integration/kubernetes/run_kubernetes_tests.sh +++ b/tests/integration/kubernetes/run_kubernetes_tests.sh @@ -91,6 +91,7 @@ else ) K8S_TEST_NORMAL_HOST_UNION=( \ + "k8s-debug-console.bats" \ "k8s-number-cpus.bats" \ "k8s-parallel.bats" \ "k8s-sandbox-vcpus-allocation.bats" \ diff --git a/tests/integration/kubernetes/runtimeclass_workloads/pod-busybox-base.yaml b/tests/integration/kubernetes/runtimeclass_workloads/pod-busybox-base.yaml new file mode 100644 index 0000000000..fe36e52cdf --- /dev/null +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-busybox-base.yaml @@ -0,0 +1,17 @@ +# +# Copyright (c) 2025 Advanced Micro Devices, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +apiVersion: v1 +kind: Pod +metadata: + name: busybox-base-pod +spec: + runtimeClassName: kata + containers: + - name: busybox-base + image: quay.io/prometheus/busybox:latest + command: ["/bin/sh", "-c"] + args: + - sleep 180