From d7f04a64a049e9aa747a63dc534d77943826baf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bombo?= Date: Tue, 25 Jul 2023 12:06:57 -0700 Subject: [PATCH] tests: k8s: Leave `runtimeclass_workloads/` alone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes it so that `setup.sh` doesn't make changes in `runtimeclass_workloads/` directly. Instead we treat that as a template directory and we use the new directory `runtimeclass_workloads_work/` as a work dir. This has two advantages: * Allows rerunning tests without the assumption that `setup.sh` must be idempotent. E.g. the `set_runtime_class()` step would break. * Doesn't pollute your git environment with a bunch of changes when developing. Signed-off-by: Aurélien Bombo --- tests/.gitignore | 1 + tests/integration/kubernetes/setup.sh | 12 +++++++++--- tests/integration/kubernetes/tests_common.sh | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/.gitignore diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000000..122d160715 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +integration/kubernetes/runtimeclass_workloads_work/ diff --git a/tests/integration/kubernetes/setup.sh b/tests/integration/kubernetes/setup.sh index 01e7d8c51a..fb68e47cbd 100755 --- a/tests/integration/kubernetes/setup.sh +++ b/tests/integration/kubernetes/setup.sh @@ -10,25 +10,31 @@ set -o pipefail kubernetes_dir=$(dirname "$(readlink -f "$0")") source "${kubernetes_dir}/../../common.bash" +reset_workloads_work_dir() { + rm -rf ${kubernetes_dir}/runtimeclass_workloads_work + cp -R ${kubernetes_dir}/runtimeclass_workloads ${kubernetes_dir}/runtimeclass_workloads_work +} + set_runtime_class() { - sed -i -e "s|runtimeClassName: kata|runtimeClassName: kata-${KATA_HYPERVISOR}|" ${kubernetes_dir}/runtimeclass_workloads/*.yaml + sed -i -e "s|runtimeClassName: kata|runtimeClassName: kata-${KATA_HYPERVISOR}|" ${kubernetes_dir}/runtimeclass_workloads_work/*.yaml } set_kernel_path() { if [[ "${KATA_HOST_OS}" = "cbl-mariner" ]]; then mariner_kernel_path="/usr/share/cloud-hypervisor/vmlinux.bin" - find ${kubernetes_dir}/runtimeclass_workloads/*.yaml -exec yq write -i {} 'metadata.annotations[io.katacontainers.config.hypervisor.kernel]' "${mariner_kernel_path}" \; + find ${kubernetes_dir}/runtimeclass_workloads_work/*.yaml -exec yq write -i {} 'metadata.annotations[io.katacontainers.config.hypervisor.kernel]' "${mariner_kernel_path}" \; fi } set_initrd_path() { if [[ "${KATA_HOST_OS}" = "cbl-mariner" ]]; then initrd_path="/opt/kata/share/kata-containers/kata-containers-initrd-mariner.img" - find ${kubernetes_dir}/runtimeclass_workloads/*.yaml -exec yq write -i {} 'metadata.annotations[io.katacontainers.config.hypervisor.initrd]' "${initrd_path}" \; + find ${kubernetes_dir}/runtimeclass_workloads_work/*.yaml -exec yq write -i {} 'metadata.annotations[io.katacontainers.config.hypervisor.initrd]' "${initrd_path}" \; fi } main() { + reset_workloads_work_dir set_runtime_class set_kernel_path set_initrd_path diff --git a/tests/integration/kubernetes/tests_common.sh b/tests/integration/kubernetes/tests_common.sh index 481cf4a570..bcf686241c 100644 --- a/tests/integration/kubernetes/tests_common.sh +++ b/tests/integration/kubernetes/tests_common.sh @@ -34,6 +34,6 @@ dragonball_limitations="https://github.com/kata-containers/kata-containers/issue export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" get_pod_config_dir() { - pod_config_dir="${BATS_TEST_DIRNAME}/runtimeclass_workloads" + pod_config_dir="${BATS_TEST_DIRNAME}/runtimeclass_workloads_work" info "k8s configured to use runtimeclass" }