@@ -30,6 +30,7 @@ import (
3030 cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
3131 "github.com/containerd/containerd"
3232 "github.com/containerd/containerd/integration/images"
33+ criopts "github.com/containerd/containerd/pkg/cri/opts"
3334 runtimespec "github.com/opencontainers/runtime-spec/specs-go"
3435 "github.com/stretchr/testify/assert"
3536 "github.com/stretchr/testify/require"
@@ -232,7 +233,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
232233 EnsureImageExists (t , pauseImage )
233234
234235 expectedSwapLimit := func (memoryLimit int64 ) * int64 {
235- return & memoryLimit
236+ if criopts .SwapControllerAvailable () {
237+ return & memoryLimit
238+ }
239+ return nil
236240 }
237241
238242 t .Log ("Create a container with memory limit" )
@@ -274,8 +278,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
274278 t .Log ("Check memory limit in cgroup" )
275279 memLimit := getCgroupMemoryLimitForTask (t , task )
276280 assert .Equal (t , uint64 (400 * 1024 * 1024 ), memLimit )
277- swapLimit := getCgroupSwapLimitForTask (t , task )
278- assert .Equal (t , uint64 (400 * 1024 * 1024 ), swapLimit )
281+ if criopts .SwapControllerAvailable () {
282+ swapLimit := getCgroupSwapLimitForTask (t , task )
283+ assert .Equal (t , uint64 (400 * 1024 * 1024 ), swapLimit )
284+ }
279285
280286 t .Log ("Update container memory limit after started" )
281287 err = runtimeService .UpdateContainerResources (cn , & runtime.LinuxContainerResources {
@@ -292,8 +298,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
292298 t .Log ("Check memory limit in cgroup" )
293299 memLimit = getCgroupMemoryLimitForTask (t , task )
294300 assert .Equal (t , uint64 (800 * 1024 * 1024 ), memLimit )
295- swapLimit = getCgroupSwapLimitForTask (t , task )
296- assert .Equal (t , uint64 (800 * 1024 * 1024 ), swapLimit )
301+ if criopts .SwapControllerAvailable () {
302+ swapLimit := getCgroupSwapLimitForTask (t , task )
303+ assert .Equal (t , uint64 (800 * 1024 * 1024 ), swapLimit )
304+ }
297305
298306}
299307
0 commit comments