diff --git a/test/e2e_node/eviction_test.go b/test/e2e_node/eviction_test.go index d20608f790d..499d9d8819f 100644 --- a/test/e2e_node/eviction_test.go +++ b/test/e2e_node/eviction_test.go @@ -510,7 +510,7 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe ginkgo.Context("", func() { ginkgo.BeforeEach(func() { // reduce memory usage in the allocatable cgroup to ensure we do not have MemoryPressure - reduceAllocatableMemoryUsage() + reduceAllocatableMemoryUsageIfCgroupv1() // Nodes do not immediately report local storage capacity // Sleep so that pods requesting local storage do not fail to schedule time.Sleep(30 * time.Second) @@ -603,7 +603,7 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe return nil }, pressureDisappearTimeout, evictionPollInterval).Should(gomega.BeNil()) - reduceAllocatableMemoryUsage() + reduceAllocatableMemoryUsageIfCgroupv1() ginkgo.By("making sure we have all the required images for testing") prePullImagesIfNeccecary() diff --git a/test/e2e_node/util.go b/test/e2e_node/util.go index 819640c150e..c06fec59488 100644 --- a/test/e2e_node/util.go +++ b/test/e2e_node/util.go @@ -468,13 +468,16 @@ func toCgroupFsName(cgroupName cm.CgroupName) string { return cgroupName.ToCgroupfs() } -// reduceAllocatableMemoryUsage uses memory.force_empty (https://lwn.net/Articles/432224/) +// reduceAllocatableMemoryUsageIfCgroupv1 uses memory.force_empty (https://lwn.net/Articles/432224/) // to make the kernel reclaim memory in the allocatable cgroup -// the time to reduce pressure may be unbounded, but usually finishes within a second -func reduceAllocatableMemoryUsage() { - cmd := fmt.Sprintf("echo 0 > /sys/fs/cgroup/memory/%s/memory.force_empty", toCgroupFsName(cm.NewCgroupName(cm.RootCgroupName, defaultNodeAllocatableCgroup))) - _, err := exec.Command("sudo", "sh", "-c", cmd).CombinedOutput() - framework.ExpectNoError(err) +// the time to reduce pressure may be unbounded, but usually finishes within a second. +// memory.force_empty is no supported in cgroupv2. +func reduceAllocatableMemoryUsageIfCgroupv1() { + if !IsCgroup2UnifiedMode() { + cmd := fmt.Sprintf("echo 0 > /sys/fs/cgroup/memory/%s/memory.force_empty", toCgroupFsName(cm.NewCgroupName(cm.RootCgroupName, defaultNodeAllocatableCgroup))) + _, err := exec.Command("sudo", "sh", "-c", cmd).CombinedOutput() + framework.ExpectNoError(err) + } } // Equivalent of featuregatetesting.SetFeatureGateDuringTest