Skip to content

Commit

Permalink
Merge pull request kata-containers#10346 from BbolroC/minor-improveme…
Browse files Browse the repository at this point in the history
…nt-k8s-tests

tests: Minor improvement k8s tests
  • Loading branch information
BbolroC authored Sep 26, 2024
2 parents 3a7f959 + 01d460a commit b1275be
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
}
3 changes: 1 addition & 2 deletions tests/integration/kubernetes/k8s-guest-pull-image.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions tests/integration/kubernetes/k8s-liveness-probes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
}
13 changes: 6 additions & 7 deletions tests/integration/kubernetes/k8s-measured-rootfs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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}")"

Expand Down Expand Up @@ -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:-}"
}
9 changes: 1 addition & 8 deletions tests/integration/kubernetes/k8s-sealed-secret.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions tests/integration/kubernetes/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/kubernetes/tests_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b1275be

Please sign in to comment.