Skip to content

Commit b170509

Browse files
committed
Update node conformance to use NoSwap
Signed-off-by: Itamar Holder <[email protected]>
1 parent bdeb80a commit b170509

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

test/e2e_node/swap_test.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,34 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
6161
f := framework.NewDefaultFramework("swap-qos")
6262
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
6363

64+
ginkgo.BeforeEach(func() {
65+
gomega.Expect(isSwapFeatureGateEnabled()).To(gomega.BeTrueBecause("NodeSwap feature should be on"))
66+
})
67+
6468
f.Context(framework.WithNodeConformance(), func() {
69+
6570
ginkgo.DescribeTable("with configuration", func(qosClass v1.PodQOSClass, memoryRequestEqualLimit bool) {
6671
ginkgo.By(fmt.Sprintf("Creating a pod of QOS class %s. memoryRequestEqualLimit: %t", qosClass, memoryRequestEqualLimit))
6772
pod := getSwapTestPod(f, qosClass, memoryRequestEqualLimit)
6873
pod = runPodAndWaitUntilScheduled(f, pod)
6974

70-
isCgroupV2 := isPodCgroupV2(f, pod)
71-
isLimitedSwap := isLimitedSwap(f, pod)
72-
isNoSwap := isNoSwap(f, pod)
75+
gomega.Expect(isPodCgroupV2(f, pod)).To(gomega.BeTrueBecause("cgroup v2 is required for swap"))
7376

74-
if !isSwapFeatureGateEnabled() || !isCgroupV2 || isNoSwap || (isLimitedSwap && (qosClass != v1.PodQOSBurstable || memoryRequestEqualLimit)) {
75-
ginkgo.By(fmt.Sprintf("Expecting no swap. isNoSwap? %t, feature gate on? %t isCgroupV2? %t is QoS burstable? %t", isNoSwap, isSwapFeatureGateEnabled(), isCgroupV2, qosClass == v1.PodQOSBurstable))
76-
expectNoSwap(pod)
77-
return
78-
}
77+
switch swapBehavior := getSwapBehavior(); swapBehavior {
78+
case types.LimitedSwap:
79+
if qosClass != v1.PodQOSBurstable || memoryRequestEqualLimit {
80+
expectNoSwap(pod)
81+
} else {
82+
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
83+
expectLimitedSwap(pod, expectedSwapLimit)
84+
}
7985

80-
if !isLimitedSwap {
81-
ginkgo.By("expecting no swap")
86+
case types.NoSwap, "":
8287
expectNoSwap(pod)
83-
return
84-
}
8588

86-
ginkgo.By("expecting limited swap")
87-
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
88-
expectLimitedSwap(pod, expectedSwapLimit)
89+
default:
90+
gomega.Expect(swapBehavior).To(gomega.Or(gomega.Equal(types.LimitedSwap), gomega.Equal(types.NoSwap)), "unknown swap behavior")
91+
}
8992
},
9093
ginkgo.Entry("QOS Best-effort", v1.PodQOSBestEffort, false),
9194
ginkgo.Entry("QOS Burstable", v1.PodQOSBurstable, false),
@@ -432,18 +435,13 @@ func calcSwapForBurstablePod(f *framework.Framework, pod *v1.Pod) int64 {
432435
return int64(swapAllocation)
433436
}
434437

435-
func isLimitedSwap(f *framework.Framework, pod *v1.Pod) bool {
436-
kubeletCfg, err := getCurrentKubeletConfig(context.Background())
437-
framework.ExpectNoError(err, "cannot get kubelet config")
438-
439-
return kubeletCfg.MemorySwap.SwapBehavior == types.LimitedSwap
440-
}
441-
442-
func isNoSwap(f *framework.Framework, pod *v1.Pod) bool {
438+
func getSwapBehavior() string {
443439
kubeletCfg, err := getCurrentKubeletConfig(context.Background())
444440
framework.ExpectNoError(err, "cannot get kubelet config")
445441

446-
return kubeletCfg.MemorySwap.SwapBehavior == types.NoSwap || kubeletCfg.MemorySwap.SwapBehavior == ""
442+
swapBehavior := kubeletCfg.MemorySwap.SwapBehavior
443+
ginkgo.By("Figuring out swap behavior: " + swapBehavior)
444+
return swapBehavior
447445
}
448446

449447
func cloneQuantity(resource *resource.Quantity) *resource.Quantity {

0 commit comments

Comments
 (0)