Merge pull request #10346 from BbolroC/minor-improvement-k8s-tests

tests: Minor improvement k8s tests
This commit is contained in:
Hyounggyu Choi
2024-09-26 17:01:32 +02:00
committed by GitHub
10 changed files with 37 additions and 54 deletions

View File

@@ -90,11 +90,5 @@ teardown() {
skip "Test skipped as KBS not setup"
fi
[ -n "${pod_name:-}" ] && kubectl describe "pod/${pod_name}" || true
[ -n "${pod_config_dir:-}" ] && kubectl delete -f "${K8S_TEST_YAML}" || true
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
teardown_common "${node}" "${node_start_time:-}"
}

View File

@@ -110,13 +110,6 @@ teardown() {
[ "${SNAPSHOTTER:-}" = "nydus" ] || skip "None snapshotter was found but this test requires one"
teardown_common "${node}" "${node_start_time:-}"
kubectl delete secret cococred --ignore-not-found
kubectl describe pods
k8s_delete_all_pods_if_any_exists || true
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
}

View File

@@ -95,11 +95,5 @@ teardown() {
[ "${SNAPSHOTTER:-}" = "nydus" ] || skip "None snapshotter was found but this test requires one"
kubectl describe pods
k8s_delete_all_pods_if_any_exists || true
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
teardown_common "${node}" "${node_start_time:-}"
}

View File

@@ -146,11 +146,5 @@ teardown() {
[ "${SNAPSHOTTER:-}" = "nydus" ] || skip "None snapshotter was found but this test requires one"
kubectl describe pods
k8s_delete_all_pods_if_any_exists || true
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
teardown_common "${node}" "${node_start_time:-}"
}

View File

@@ -230,8 +230,7 @@ teardown() {
[ "${SNAPSHOTTER:-}" = "nydus" ] || skip "None snapshotter was found but this test requires one"
kubectl describe pods
k8s_delete_all_pods_if_any_exists || true
teardown_common "${node}" "${node_start_time:-}"
kubectl delete --ignore-not-found pvc trusted-pvc
kubectl delete --ignore-not-found pv trusted-block-pv
kubectl delete --ignore-not-found storageclass local-storage

View File

@@ -93,14 +93,7 @@ setup() {
teardown() {
# Debugging information
kubectl describe "pod/$pod_name"
kubectl delete pod "$pod_name"
rm -f "${yaml_file}"
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
teardown_common "${node}" "${node_start_time:-}"
}

View File

@@ -22,13 +22,6 @@ setup() {
setup_common
}
teardown() {
check_and_skip
kubectl describe -f "${pod_config}" || true
kubectl delete -f "${pod_config}" || true
}
@test "Test cannnot launch pod with measured boot enabled and incorrect hash" {
pod_config="$(new_pod_config nginx "kata-${KATA_HYPERVISOR}")"
@@ -57,3 +50,9 @@ teardown() {
assert_logs_contain "$node" kata "$node_start_time" \
'verity: .* metadata block .* is corrupted'
}
teardown() {
check_and_skip
teardown_common "${node}" "${node_start_time:-}"
}

View File

@@ -107,14 +107,7 @@ teardown() {
skip "Test skipped as KBS not setup"
fi
[ -n "${pod_name:-}" ] && kubectl describe "pod/${pod_name}" || true
[ -n "${pod_config_dir:-}" ] && kubectl delete -f "${K8S_TEST_YAML}" || true
teardown_common "${node}" "${node_start_time:-}"
kubectl delete secret sealed-secret --ignore-not-found
kubectl delete secret not-sealed-secret --ignore-not-found
if [[ -n "${node_start_time:-}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
}

View File

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

View File

@@ -359,3 +359,23 @@ pod_exec_blocked_command() {
(echo "${exec_output}" | grep "ExecProcessRequest is blocked by policy" > /dev/null) || die "exec was not blocked by policy!"
}
# Common teardown for tests.
#
# Parameters:
# $1 - node name where kata is installed
# $2 - start time at the node for the sake of fetching logs
#
teardown_common() {
local node="$1"
local node_start_time="$2"
kubectl describe pods
k8s_delete_all_pods_if_any_exists || true
# Print the node journal since the test start time if a bats test is not completed
if [[ -n "${node_start_time}" && -z "$BATS_TEST_COMPLETED" ]]; then
echo "DEBUG: system logs of node '$node' since test start time ($node_start_time)"
exec_host "${node}" journalctl -x -t "kata" --since '"'$node_start_time'"' || true
fi
}