From 91f11a15466738e98782ad626fa47102aa6372d0 Mon Sep 17 00:00:00 2001 From: Yushuo Date: Sun, 9 Jul 2023 22:17:10 +0800 Subject: [PATCH] bugfix: plus default_memory when calculating mem size We've noticed this caused regressions with the k8s-oom tests, and then decided to take a step back and do this in the same way it was done before 67972ec48a40434fd7c3883c4538cc1d328ede40. And by doing this we can re-enable the k8s-oom.bats tests, which is done as part of this PR. Fixes: #7271 Depends-on: github.com/kata-containers/tests#5705 Signed-off-by: Yushuo --- src/runtime-rs/crates/resource/src/cpu_mem/initial_size.rs | 7 ++++++- tests/integration/kubernetes/k8s-oom.bats | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/runtime-rs/crates/resource/src/cpu_mem/initial_size.rs b/src/runtime-rs/crates/resource/src/cpu_mem/initial_size.rs index 53eccc52bdb4..2a8b6e60083e 100644 --- a/src/runtime-rs/crates/resource/src/cpu_mem/initial_size.rs +++ b/src/runtime-rs/crates/resource/src/cpu_mem/initial_size.rs @@ -105,7 +105,12 @@ impl InitialSizeManager { hv.cpu_info.default_vcpus = self.resource.vcpu as i32 } if self.resource.mem_mb > 0 { - hv.memory_info.default_memory = self.resource.mem_mb; + // since the memory overhead introduced by kata-agent and system components + // will really affect the amount of memory the user can use, so we choose to + // plus the default_memory here, instead of overriding it. + // (if we override the default_memory here, and user apllications still + // use memory as they orignally expected, it would be easy to OOM.) + hv.memory_info.default_memory += self.resource.mem_mb; } Ok(()) } diff --git a/tests/integration/kubernetes/k8s-oom.bats b/tests/integration/kubernetes/k8s-oom.bats index 5f45ad78a7de..f89b761f807d 100644 --- a/tests/integration/kubernetes/k8s-oom.bats +++ b/tests/integration/kubernetes/k8s-oom.bats @@ -9,15 +9,11 @@ load "${BATS_TEST_DIRNAME}/../../common.bash" load "${BATS_TEST_DIRNAME}/tests_common.sh" setup() { - [ "${KATA_HYPERVISOR}" == "dragonball" ] && skip "Test is currently failing, see: https://github.com/kata-containers/kata-containers/issues/7271" - pod_name="pod-oom" get_pod_config_dir } @test "Test OOM events for pods" { - [ "${KATA_HYPERVISOR}" == "dragonball" ] && skip "Test is currently failing, see: https://github.com/kata-containers/kata-containers/issues/7271" - # Create pod kubectl create -f "${pod_config_dir}/$pod_name.yaml" @@ -33,8 +29,6 @@ setup() { } teardown() { - [ "${KATA_HYPERVISOR}" == "dragonball" ] && skip "Test is currently failing, see: https://github.com/kata-containers/kata-containers/issues/7271" - # Debugging information kubectl describe "pod/$pod_name" kubectl get "pod/$pod_name" -o yaml