Merge pull request #7893 from AkihiroSuda/fix-7890

Fix TestUpdateContainerResources_Memory* on cgroup v2 hosts
This commit is contained in:
Akihiro Suda 2023-01-03 19:52:50 +09:00 committed by GitHub
commit 88c8480a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,7 +81,7 @@ func getCgroupSwapLimitForTask(t *testing.T, task containerd.Task) uint64 {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return stat.Memory.SwapLimit return stat.Memory.SwapLimit + stat.Memory.UsageLimit
} }
cgroup, err := cgroup1.Load(cgroup1.PidPath(int(task.Pid()))) cgroup, err := cgroup1.Load(cgroup1.PidPath(int(task.Pid())))
if err != nil { if err != nil {
@ -171,11 +171,6 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
expectedBaseSwap := baseSwapLimit expectedBaseSwap := baseSwapLimit
expectedIncreasedSwap := increasedSwapLimit expectedIncreasedSwap := increasedSwapLimit
if cgroups.Mode() == cgroups.Unified {
expectedBaseSwap = baseSwapLimit - memoryLimit
expectedIncreasedSwap = increasedSwapLimit - memoryLimit
}
t.Log("Create a container with memory limit but no swap") t.Log("Create a container with memory limit but no swap")
cnConfig := ContainerConfig( cnConfig := ContainerConfig(
"container", "container",
@ -237,9 +232,6 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
expectedSwapLimit := func(memoryLimit int64) *int64 { expectedSwapLimit := func(memoryLimit int64) *int64 {
if cgroups.Mode() == cgroups.Unified {
memoryLimit = 0
}
return &memoryLimit return &memoryLimit
} }