From 849253e55c9984d6afc065eb266f260f0c00ea10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 9 Nov 2023 21:59:59 +0100 Subject: [PATCH] tests: Add a simple test to check the VMM vcpu allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've done some changes in the VMM vcpu allocation, let's introduce basic tests to make sure that we're getting the expected behaviour. The test consists in checking 3 scenarios: * default_vcpus = 0 | no limits set * this should allocate 1 vcpu * default_vcpus = 0.75 | limits set to 0.25 * this should allocate 1 vcpu * default_vcpus = 0.75 | limits set to 1.2 * this should allocate 2 vcpus The tests are very basic, but they do ensure we're rounding things up to what the new logic is supposed to do. Signed-off-by: Fabiano FidĂȘncio --- tests/integration/kubernetes/gha-run.sh | 4 +- .../k8s-sandbox-vcpus-allocation.bats | 40 ++++++++++++++ .../kubernetes/run_kubernetes_tests.sh | 1 + .../pod-sandbox-vcpus-allocation.yaml | 54 +++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats create mode 100644 tests/integration/kubernetes/runtimeclass_workloads/pod-sandbox-vcpus-allocation.yaml diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index 7dd65644a3..b9ab940984 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -117,9 +117,11 @@ function deploy_kata() { yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[4].value' --tag '!!str' "true" # Let the `kata-deploy` create the default `kata` runtime class yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[5].value' --tag '!!str' "true" + # Enable 'default_vcpus' hypervisor annotation + yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[6].value' "default_vcpus" if [ "${KATA_HOST_OS}" = "cbl-mariner" ]; then - yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[6].value' "initrd kernel" + yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[6].value' "initrd kernel default_vcpus" yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[+].name' "HOST_OS" yq write -i "${tools_dir}/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" 'spec.template.spec.containers[0].env[-1].value' "${KATA_HOST_OS}" fi diff --git a/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats b/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats new file mode 100644 index 0000000000..2f0a872c00 --- /dev/null +++ b/tests/integration/kubernetes/k8s-sandbox-vcpus-allocation.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats +# +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +load "${BATS_TEST_DIRNAME}/../../common.bash" +load "${BATS_TEST_DIRNAME}/tests_common.sh" + +setup() { + [ "${KATA_HYPERVISOR}" == "dragonball" ] && \ + skip "runtime-rs is still using the old vcpus allocation algorithm, skipping the test" + + 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 ) +} + +@test "Check the number vcpus are correctly allocated to the sandbox" { + # Create the pods + kubectl create -f "${pod_config_dir}/pod-sandbox-vcpus-allocation.yaml" + + # Check the pods + for i in {0..2}; do + kubectl wait --for=jsonpath='{.status.conditions[0].reason}'=PodCompleted --timeout=$timeout pod ${pods[$i]} + [ `kubectl logs ${pods[$i]}` -eq ${expected_vcpus[$i]} ] + done +} + +teardown() { + [ "${KATA_HYPERVISOR}" == "dragonball" ] && \ + skip "runtime-rs is still using the old vcpus allocation algorithm, skipping the test" + + for pod in "${pods[@]}"; do + kubectl logs ${pod} + done + + kubectl delete -f "${pod_config_dir}/pod-sandbox-vcpus-allocation.yaml" +} diff --git a/tests/integration/kubernetes/run_kubernetes_tests.sh b/tests/integration/kubernetes/run_kubernetes_tests.sh index 36f7a56c9d..b16c22ae64 100644 --- a/tests/integration/kubernetes/run_kubernetes_tests.sh +++ b/tests/integration/kubernetes/run_kubernetes_tests.sh @@ -60,6 +60,7 @@ else K8S_TEST_NORMAL_HOST_UNION=( \ "k8s-number-cpus.bats" \ "k8s-parallel.bats" \ + "k8s-sandbox-vcpus-allocation.bats" \ "k8s-scale-nginx.bats" \ ) diff --git a/tests/integration/kubernetes/runtimeclass_workloads/pod-sandbox-vcpus-allocation.yaml b/tests/integration/kubernetes/runtimeclass_workloads/pod-sandbox-vcpus-allocation.yaml new file mode 100644 index 0000000000..0730840fad --- /dev/null +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-sandbox-vcpus-allocation.yaml @@ -0,0 +1,54 @@ +# +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: v1 +kind: Pod +metadata: + name: vcpus-less-than-one-with-no-limits + annotations: + io.katacontainers.config.hypervisor.default_vcpus: "0" +spec: + runtimeClassName: kata + containers: + - name: vcpus-less-than-one-with-no-limits + image: quay.io/prometheus/busybox:latest + command: ['nproc', '--all'] + restartPolicy: Never +--- +apiVersion: v1 +kind: Pod +metadata: + name: vcpus-less-than-one-with-limits + annotations: + io.katacontainers.config.hypervisor.default_vcpus: "0.75" +spec: + runtimeClassName: kata + containers: + - name: vcpus-less-than-one-with-limits + image: quay.io/prometheus/busybox:latest + resources: + limits: + cpu: "0.25" + command: ['nproc', '--all'] + restartPolicy: Never +--- +apiVersion: v1 +kind: Pod +metadata: + name: vcpus-more-than-one-with-limits + annotations: + io.katacontainers.config.hypervisor.default_vcpus: "0.75" +spec: + runtimeClassName: kata + containers: + - name: vcpus-more-than-one-with-limits + image: quay.io/prometheus/busybox:latest + resources: + limits: + cpu: "1.2" + command: ['nproc', '--all'] + restartPolicy: Never +---