Merge pull request #11519 from wainersm/tests_teardown_common

tests/k8s: instrument some tests for debugging
This commit is contained in:
Steve Horsman
2025-07-14 13:20:01 +01:00
committed by GitHub
4 changed files with 28 additions and 10 deletions

View File

@@ -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:-}"
}

View File

@@ -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}
}

View File

@@ -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:-}"
}

View File

@@ -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}"
}