From c6075c862709bed05f374725b39eff406d1ee4b8 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Wed, 25 Oct 2023 17:59:10 -0300 Subject: [PATCH] tests/k8s: add setup common Bring the setup_common() from CCv0 branch test's integration/kubernetes/confidential/tests_common.sh. It should be used to reduce boilerplates on the setup() of the tests. Unlike the original code, this won't export the `test_start_time` variable as it wouldn't be accurate to grab logs from the worker nodes due date/time mismatch between the running tests machine and the worker node. The function export the `node` variable which holds the name of a random node which has kata installed. Apart from that, it exports the `node_start_time` which capture the date/time when the test started, relative to the `node`. Tests that should inspect the logs can schedule pods/resources to the `node` and use `node_start_time` as the value reference to grep the logs. Fixes #7590 Co-authored-by: stevenhorsman Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/tests_common.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integration/kubernetes/tests_common.sh b/tests/integration/kubernetes/tests_common.sh index 922286ada5..b5fef531d9 100644 --- a/tests/integration/kubernetes/tests_common.sh +++ b/tests/integration/kubernetes/tests_common.sh @@ -33,6 +33,23 @@ dragonball_limitations="https://github.com/kata-containers/kata-containers/issue # overwrite it. export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" +# Common setup for tests. +# +# Global variables exported: +# $node - random picked node that has kata installed +# $node_start_date - start date/time at the $node for the sake of +# fetching logs +# +setup_common() { + node=$(get_one_kata_node) + [ -n "$node" ] + node_start_time=$(exec_host "$node" date +\"%Y-%m-%d %H:%M:%S\") + [ -n "$node_start_time" ] + export node node_start_time + + k8s_delete_all_pods_if_any_exists || true +} + get_pod_config_dir() { pod_config_dir="${BATS_TEST_DIRNAME}/runtimeclass_workloads_work" info "k8s configured to use runtimeclass"