@@ -71,22 +71,9 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
71
71
pod = runPodAndWaitUntilScheduled (f , pod )
72
72
73
73
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" )
74
75
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 )
90
77
},
91
78
ginkgo .Entry ("QOS Best-effort" , v1 .PodQOSBestEffort , false ),
92
79
ginkgo .Entry ("QOS Burstable" , v1 .PodQOSBurstable , false ),
@@ -96,6 +83,39 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
96
83
})
97
84
98
85
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
+
99
119
// These tests assume the following, and will fail otherwise:
100
120
// - The node is provisioned with swap
101
121
// - The node is configured with cgroup v2
@@ -138,16 +158,7 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
138
158
})
139
159
140
160
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 )
151
162
152
163
getRequestBySwapLimit := func (swapPercentage int64 ) * resource.Quantity {
153
164
gomega .ExpectWithOffset (1 , swapPercentage ).To (gomega .And (
0 commit comments