fixup: handle diff between cgroupsv1 and v2
Signed-off-by: Danielle Lancashire <dani@builds.terrible.systems>
This commit is contained in:
parent
2fa4e9c0e2
commit
c5b0a18b6e
@ -142,6 +142,14 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
|||||||
baseSwapLimit := int64(200 * 1024 * 1024)
|
baseSwapLimit := int64(200 * 1024 * 1024)
|
||||||
increasedSwapLimit := int64(256 * 1024 * 1024)
|
increasedSwapLimit := int64(256 * 1024 * 1024)
|
||||||
|
|
||||||
|
expectedBaseSwap := baseSwapLimit
|
||||||
|
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",
|
||||||
@ -160,13 +168,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
|||||||
spec, err := container.Spec(context.Background())
|
spec, err := container.Spec(context.Background())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
checkMemoryLimit(t, spec, memoryLimit)
|
checkMemoryLimit(t, spec, memoryLimit)
|
||||||
checkMemorySwapLimit(t, spec, &baseSwapLimit)
|
checkMemorySwapLimit(t, spec, &expectedBaseSwap)
|
||||||
|
|
||||||
t.Log("Update container swap limit after created")
|
|
||||||
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
|
||||||
MemorySwapLimitInBytes: baseSwapLimit,
|
|
||||||
}, nil)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
t.Log("Check memory limit in container OCI spec")
|
t.Log("Check memory limit in container OCI spec")
|
||||||
spec, err = container.Spec(context.Background())
|
spec, err = container.Spec(context.Background())
|
||||||
@ -183,7 +185,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
|||||||
memLimit := getCgroupMemoryLimitForTask(t, task)
|
memLimit := getCgroupMemoryLimitForTask(t, task)
|
||||||
swapLimit := getCgroupSwapLimitForTask(t, task)
|
swapLimit := getCgroupSwapLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(memoryLimit), memLimit)
|
assert.Equal(t, uint64(memoryLimit), memLimit)
|
||||||
assert.Equal(t, uint64(baseSwapLimit-memoryLimit), swapLimit)
|
assert.Equal(t, uint64(expectedBaseSwap), swapLimit)
|
||||||
|
|
||||||
t.Log("Update container memory limit after started")
|
t.Log("Update container memory limit after started")
|
||||||
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
||||||
@ -198,7 +200,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
|||||||
|
|
||||||
t.Log("Check memory limit in cgroup")
|
t.Log("Check memory limit in cgroup")
|
||||||
swapLimit = getCgroupSwapLimitForTask(t, task)
|
swapLimit = getCgroupSwapLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(increasedSwapLimit-memoryLimit), swapLimit)
|
assert.Equal(t, uint64(expectedIncreasedSwap), swapLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user