From c8f40fe12ce5179356153f38278b533e6e21b12d Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Tue, 1 Jul 2025 18:13:29 -0300 Subject: [PATCH 1/4] tests/k8s: call teardown_common in k8s-sandbox-vcpus-allocation.bats The teardown_common will print the description of the running pods, kill them all and print the system's syslogs afterwards. Signed-off-by: Wainer dos Santos Moschetta --- .../integration/kubernetes/k8s-sandbox-vcpus-allocation.bats | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats b/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats index a59b4085a4..1dbc0a7c9b 100644 --- a/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats +++ b/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats @@ -6,6 +6,7 @@ # load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/lib.sh" load "${BATS_TEST_DIRNAME}/tests_common.sh" setup() { @@ -14,11 +15,13 @@ setup() { [ "${KATA_HYPERVISOR}" = "qemu-runtime-rs" ] && skip "Requires CPU hotplug which isn't supported on ${KATA_HYPERVISOR} yet" [ "$(uname -m)" == "aarch64" ] && skip "See: https://github.com/kata-containers/kata-containers/issues/10928" + setup_common get_pod_config_dir pods=( "vcpus-less-than-one-with-no-limits" "vcpus-less-than-one-with-limits" "vcpus-more-than-one-with-limits" ) expected_vcpus=( 1 1 2 ) yaml_file="${pod_config_dir}/pod-sandbox-vcpus-allocation.yaml" + set_node "$yaml_file" "$node" add_allow_all_policy_to_yaml "${yaml_file}" } @@ -45,5 +48,5 @@ teardown() { kubectl logs ${pod} done - kubectl delete -f "${yaml_file}" + teardown_common "${node}" "${node_start_time:-}" } From 806d63d1d8584579bb0248906a0b4c8337968565 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Wed, 2 Jul 2025 16:36:48 -0300 Subject: [PATCH 2/4] tests/k8s: call teardown_common in k8s-credentials-secrets.bats The teardown_common will print the description of the running pods, kill them all and print the system's syslogs afterwards. Signed-off-by: Wainer dos Santos Moschetta --- .../kubernetes/k8s-credentials-secrets.bats | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integration/kubernetes/k8s-credentials-secrets.bats b/tests/integration/kubernetes/k8s-credentials-secrets.bats index 5969c38b29..7035c70fb9 100644 --- a/tests/integration/kubernetes/k8s-credentials-secrets.bats +++ b/tests/integration/kubernetes/k8s-credentials-secrets.bats @@ -6,16 +6,19 @@ # load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/lib.sh" load "${BATS_TEST_DIRNAME}/tests_common.sh" setup() { [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" [ "${KATA_HYPERVISOR}" == "fc" ] && skip "test not working see: ${fc_limitations}" + setup_common get_pod_config_dir # Add policy to pod-secret.yaml. pod_yaml_file="${pod_config_dir}/pod-secret.yaml" + set_node "$pod_yaml_file" "$node" pod_cmd="ls /tmp/secret-volume" pod_exec_command=(sh -c "${pod_cmd}") pod_policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")" @@ -28,6 +31,7 @@ setup() { # TODO: auto-generate policy for this pod YAML after solving # https://github.com/kata-containers/kata-containers/issues/10033 pod_env_yaml_file="${pod_config_dir}/pod-secret-env.yaml" + set_node "$pod_env_yaml_file" "$node" pod_env_cmd="printenv" pod_env_exec_command=(sh -c "${pod_env_cmd}") add_allow_all_policy_to_yaml "${pod_env_yaml_file}" @@ -69,12 +73,9 @@ teardown() { [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" [ "${KATA_HYPERVISOR}" == "fc" ] && skip "test not working see: ${fc_limitations}" - # Debugging information - kubectl describe "pod/$pod_name" - kubectl describe "pod/$second_pod_name" - - kubectl delete pod "$pod_name" "$second_pod_name" kubectl delete secret "$secret_name" delete_tmp_policy_settings_dir "${pod_policy_settings_dir}" + + teardown_common "${node}" "${node_start_time:-}" } From 8dfeed77cd088d1996170ff16852f5ed1714b4ca Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Wed, 2 Jul 2025 17:22:13 -0300 Subject: [PATCH 3/4] tests/k8s: add handler for Job in set_node() Set the node in the spec template of a Job manifest, allowing to use set_node() on tests like k8s-parallel.bats Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/lib.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/integration/kubernetes/lib.sh b/tests/integration/kubernetes/lib.sh index bfc4c3c3d9..c726a0c14c 100644 --- a/tests/integration/kubernetes/lib.sh +++ b/tests/integration/kubernetes/lib.sh @@ -340,10 +340,19 @@ set_container_command() { set_node() { local yaml="$1" local node="$2" + local kind + local spec [ -n "$node" ] || return 1 + kind="$(yq -r '.kind' "${yaml}")" + if [[ "${kind}" = "Job" ]]; then + spec=".spec.template.spec.nodeName" + else + spec=".spec.nodeName" + fi + yq -i \ - ".spec.nodeName = \"$node\"" \ + "${spec} = \"$node\"" \ "${yaml}" } From f0f1974e149fb18c2017b8221c8f28f928ebf54f Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Wed, 2 Jul 2025 16:49:35 -0300 Subject: [PATCH 4/4] tests/k8s: call teardown_common in k8s-parallel.bats The teardown_common will print the description of the running pods, kill them all and print the system's syslogs afterwards. Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/k8s-parallel.bats | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/integration/kubernetes/k8s-parallel.bats b/tests/integration/kubernetes/k8s-parallel.bats index f11bd5fb3d..ef02309058 100644 --- a/tests/integration/kubernetes/k8s-parallel.bats +++ b/tests/integration/kubernetes/k8s-parallel.bats @@ -6,9 +6,11 @@ # load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/lib.sh" load "${BATS_TEST_DIRNAME}/tests_common.sh" setup() { + setup_common get_pod_config_dir job_name="jobtest" names=( "test1" "test2" "test3" ) @@ -21,6 +23,7 @@ setup() { for i in "${names[@]}"; do yaml_file="${pod_config_dir}/job-$i.yaml" sed "s/\$ITEM/$i/" ${pod_config_dir}/job-template.yaml > ${yaml_file} + set_node "$yaml_file" "$node" auto_generate_policy "${policy_settings_dir}" "${yaml_file}" done } @@ -44,13 +47,15 @@ setup() { } teardown() { - # Delete jobs - kubectl delete jobs -l jobgroup=${job_name} - # Remove generated yaml files for i in "${names[@]}"; do rm -f ${pod_config_dir}/job-$i.yaml done delete_tmp_policy_settings_dir "${policy_settings_dir}" + + teardown_common + + # Delete jobs + kubectl delete jobs -l jobgroup=${job_name} }