From 6aa3517393da94401e67f024aaba09ff01c202cb Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Thu, 24 Jul 2025 15:59:06 +0800 Subject: [PATCH] tests: Prevent the shim from being killed in k8s-oom test The actual memory usage on the host is equal to the hypervisor memory usage plus the user memory usage. An OOM killer might kill the shim when the memory limit on host is same with that of container and the container consumes all available memory. In this case, the containerd will never receive OOM event, but get "task exit" event. That makes the `k8s-oom.bats` test fail. The fix is to add a new container to increase the sandbox memory limit. When the container "oom-test" is killed by OOM killer, there is still available memory for the shim, so it will not be killed. Signed-off-by: Xuewei Niu --- tests/integration/kubernetes/k8s-oom.bats | 7 ++++++- .../kubernetes/runtimeclass_workloads/pod-oom.yaml | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/integration/kubernetes/k8s-oom.bats b/tests/integration/kubernetes/k8s-oom.bats index 52c0eeee3a..d2c9de8ab0 100644 --- a/tests/integration/kubernetes/k8s-oom.bats +++ b/tests/integration/kubernetes/k8s-oom.bats @@ -24,7 +24,12 @@ setup() { kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" # Check if OOMKilled - cmd="kubectl get pods "$pod_name" -o jsonpath='{.status.containerStatuses[0].state.terminated.reason}' | grep OOMKilled" + container_name=$(kubectl get pod "$pod_name" -o jsonpath='{.status.containerStatuses[0].name}') + if [[ $container_name == "oom-test" ]]; then + cmd="kubectl get pods "$pod_name" -o jsonpath='{.status.containerStatuses[0].state.terminated.reason}' | grep OOMKilled" + else + cmd="kubectl get pods "$pod_name" -o jsonpath='{.status.containerStatuses[1].state.terminated.reason}' | grep OOMKilled" + fi waitForProcess "$wait_time" "$sleep_time" "$cmd" diff --git a/tests/integration/kubernetes/runtimeclass_workloads/pod-oom.yaml b/tests/integration/kubernetes/runtimeclass_workloads/pod-oom.yaml index 26badb3bc8..c0316616f7 100644 --- a/tests/integration/kubernetes/runtimeclass_workloads/pod-oom.yaml +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-oom.yaml @@ -17,6 +17,16 @@ spec: name: oom-test command: ["/bin/sh"] args: ["-c", "sleep 2; stress --vm 2 --vm-bytes 500M --timeout 30s"] + resources: + limits: + memory: 400Mi + requests: + memory: 400Mi + - image: quay.io/kata-containers/sysbench-kata:latest + imagePullPolicy: IfNotPresent + name: not-oom + command: ["/bin/sh"] + args: ["-c", "sleep inf"] resources: limits: memory: 500Mi