Skip to content

Commit 5a00d28

Browse files
committed
Fix TestUpdateContainerResources_Memory* on cgroup v2 hosts
Fix issue 7890 Tested on Ubuntu 22.10, with swapon and swapoff: ``` $ GITHUB_WORKSPACE="" ENABLE_CRI_SANDBOXES="" CONTAINERD_RUNTIME=io.containerd.runc.v2 FOCUS=TestUpdateContainerResources_Memory make cri-integration ... === RUN TestUpdateContainerResources_MemorySwap container_update_resources_test.go:161: Create a sandbox INFO[0000] Using the following image list: {Alpine:docker.io/library/alpine:latest BusyBox:docker.io/library/busybox:latest Pause:registry.k8s.io/pause:3.8 ResourceConsumer:registry.k8s.io/e2e-test-images/resource-consumer:1.10 VolumeCopyUp:ghcr.io/containerd/volume-copy-up:2.1 VolumeOwnership:ghcr.io/containerd/volume-ownership:2.1} main_test.go:663: Image "registry.k8s.io/pause:3.8" already exists, not pulling. container_update_resources_test.go:174: Create a container with memory limit but no swap container_update_resources_test.go:186: Check memory limit in container OCI spec container_update_resources_test.go:194: Check memory limit in container OCI spec container_update_resources_test.go:200: Start the container container_update_resources_test.go:205: Check memory limit in cgroup container_update_resources_test.go:211: Update container memory limit after started container_update_resources_test.go:217: Check memory limit in container OCI spec container_update_resources_test.go:222: Check memory limit in cgroup --- PASS: TestUpdateContainerResources_MemorySwap (0.88s) === RUN TestUpdateContainerResources_MemoryLimit container_update_resources_test.go:228: Create a sandbox main_test.go:663: Image "registry.k8s.io/pause:3.8" already exists, not pulling. container_update_resources_test.go:238: Create a container with memory limit container_update_resources_test.go:249: Check memory limit in container OCI spec container_update_resources_test.go:257: Update container memory limit after created container_update_resources_test.go:263: Check memory limit in container OCI spec container_update_resources_test.go:269: Start the container container_update_resources_test.go:274: Check memory limit in cgroup container_update_resources_test.go:280: Update container memory limit after started container_update_resources_test.go:286: Check memory limit in container OCI spec container_update_resources_test.go:292: Check memory limit in cgroup --- PASS: TestUpdateContainerResources_MemoryLimit (0.91s) PASS ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent d769f03 commit 5a00d28

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

integration/container_update_resources_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func getCgroupSwapLimitForTask(t *testing.T, task containerd.Task) uint64 {
8181
if err != nil {
8282
t.Fatal(err)
8383
}
84-
return stat.Memory.SwapLimit
84+
return stat.Memory.SwapLimit + stat.Memory.UsageLimit
8585
}
8686
cgroup, err := cgroup1.Load(cgroup1.PidPath(int(task.Pid())))
8787
if err != nil {
@@ -171,11 +171,6 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
171171
expectedBaseSwap := baseSwapLimit
172172
expectedIncreasedSwap := increasedSwapLimit
173173

174-
if cgroups.Mode() == cgroups.Unified {
175-
expectedBaseSwap = baseSwapLimit - memoryLimit
176-
expectedIncreasedSwap = increasedSwapLimit - memoryLimit
177-
}
178-
179174
t.Log("Create a container with memory limit but no swap")
180175
cnConfig := ContainerConfig(
181176
"container",
@@ -237,9 +232,6 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
237232
EnsureImageExists(t, pauseImage)
238233

239234
expectedSwapLimit := func(memoryLimit int64) *int64 {
240-
if cgroups.Mode() == cgroups.Unified {
241-
memoryLimit = 0
242-
}
243235
return &memoryLimit
244236
}
245237

0 commit comments

Comments
 (0)