Skip to content

Commit e9b1a5e

Browse files
committed
Expect NoSwap on NodeConformance, test LimitedSwap only in serial tests
Signed-off-by: Itamar Holder <[email protected]>
1 parent ab5f84e commit e9b1a5e

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

test/e2e_node/swap_test.go

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,9 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
7171
pod = runPodAndWaitUntilScheduled(f, pod)
7272

7373
gomega.Expect(isPodCgroupV2(f, pod)).To(gomega.BeTrueBecause("cgroup v2 is required for swap"))
74+
gomega.Expect(getSwapBehavior()).To(gomega.Or(gomega.Equal(types.NoSwap), gomega.BeEmpty()), "NodeConformance is expected to run with NoSwap")
7475

75-
switch swapBehavior := getSwapBehavior(); swapBehavior {
76-
case types.LimitedSwap:
77-
if qosClass != v1.PodQOSBurstable || memoryRequestEqualLimit {
78-
expectNoSwap(f, pod)
79-
} else {
80-
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
81-
expectLimitedSwap(f, pod, expectedSwapLimit)
82-
}
83-
84-
case types.NoSwap, "":
85-
expectNoSwap(f, pod)
86-
87-
default:
88-
gomega.Expect(swapBehavior).To(gomega.Or(gomega.Equal(types.LimitedSwap), gomega.Equal(types.NoSwap)), "unknown swap behavior")
89-
}
76+
expectNoSwap(f, pod)
9077
},
9178
ginkgo.Entry("QOS Best-effort", v1.PodQOSBestEffort, false),
9279
ginkgo.Entry("QOS Burstable", v1.PodQOSBurstable, false),
@@ -96,6 +83,39 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
9683
})
9784

9885
f.Context(framework.WithSerial(), func() {
86+
87+
enableLimitedSwap := func(ctx context.Context, initialConfig *config.KubeletConfiguration) {
88+
msg := "swap behavior is already set to LimitedSwap"
89+
90+
if swapBehavior := initialConfig.MemorySwap.SwapBehavior; swapBehavior != types.LimitedSwap {
91+
initialConfig.MemorySwap.SwapBehavior = types.LimitedSwap
92+
msg = "setting swap behavior to LimitedSwap"
93+
}
94+
95+
ginkgo.By(msg)
96+
}
97+
98+
f.Context("Basic functionality", func() {
99+
tempSetCurrentKubeletConfig(f, enableLimitedSwap)
100+
101+
ginkgo.DescribeTable("with configuration", func(qosClass v1.PodQOSClass, memoryRequestEqualLimit bool) {
102+
ginkgo.By(fmt.Sprintf("Creating a pod of QOS class %s. memoryRequestEqualLimit: %t", qosClass, memoryRequestEqualLimit))
103+
pod := getSwapTestPod(f, qosClass, memoryRequestEqualLimit)
104+
pod = runPodAndWaitUntilScheduled(f, pod)
105+
106+
gomega.Expect(isPodCgroupV2(f, pod)).To(gomega.BeTrueBecause("cgroup v2 is required for swap"))
107+
gomega.Expect(getSwapBehavior()).To(gomega.Equal(types.LimitedSwap))
108+
109+
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
110+
expectLimitedSwap(f, pod, expectedSwapLimit)
111+
},
112+
ginkgo.Entry("QOS Best-effort", v1.PodQOSBestEffort, false),
113+
ginkgo.Entry("QOS Burstable", v1.PodQOSBurstable, false),
114+
ginkgo.Entry("QOS Burstable with memory request equals to limit", v1.PodQOSBurstable, true),
115+
ginkgo.Entry("QOS Guaranteed", v1.PodQOSGuaranteed, false),
116+
)
117+
})
118+
99119
// These tests assume the following, and will fail otherwise:
100120
// - The node is provisioned with swap
101121
// - The node is configured with cgroup v2
@@ -138,16 +158,7 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
138158
})
139159

140160
ginkgo.Context("LimitedSwap", func() {
141-
tempSetCurrentKubeletConfig(f, func(ctx context.Context, initialConfig *config.KubeletConfiguration) {
142-
msg := "swap behavior is already set to LimitedSwap"
143-
144-
if swapBehavior := initialConfig.MemorySwap.SwapBehavior; swapBehavior != types.LimitedSwap {
145-
initialConfig.MemorySwap.SwapBehavior = types.LimitedSwap
146-
msg = "setting swap behavior to LimitedSwap"
147-
}
148-
149-
ginkgo.By(msg)
150-
})
161+
tempSetCurrentKubeletConfig(f, enableLimitedSwap)
151162

152163
getRequestBySwapLimit := func(swapPercentage int64) *resource.Quantity {
153164
gomega.ExpectWithOffset(1, swapPercentage).To(gomega.And(

0 commit comments

Comments
 (0)