Skip to content

Commit 5594f70

Browse files
AkihiroSudathaJeztah
authored andcommitted
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]> (cherry picked from commit 5a00d28) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent cf13b64 commit 5594f70

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
@@ -80,7 +80,7 @@ func getCgroupSwapLimitForTask(t *testing.T, task containerd.Task) uint64 {
8080
if err != nil {
8181
t.Fatal(err)
8282
}
83-
return stat.Memory.SwapLimit
83+
return stat.Memory.SwapLimit + stat.Memory.UsageLimit
8484
}
8585
cgroup, err := cgroups.Load(cgroups.V1, cgroups.PidPath(int(task.Pid())))
8686
if err != nil {
@@ -169,11 +169,6 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
169169
expectedBaseSwap := baseSwapLimit
170170
expectedIncreasedSwap := increasedSwapLimit
171171

172-
if cgroups.Mode() == cgroups.Unified {
173-
expectedBaseSwap = baseSwapLimit - memoryLimit
174-
expectedIncreasedSwap = increasedSwapLimit - memoryLimit
175-
}
176-
177172
t.Log("Create a container with memory limit but no swap")
178173
cnConfig := ContainerConfig(
179174
"container",
@@ -235,9 +230,6 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
235230
EnsureImageExists(t, pauseImage)
236231

237232
expectedSwapLimit := func(memoryLimit int64) *int64 {
238-
if cgroups.Mode() == cgroups.Unified {
239-
memoryLimit = 0
240-
}
241233
return &memoryLimit
242234
}
243235

0 commit comments

Comments
 (0)