@@ -61,31 +61,34 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
61
61
f := framework .NewDefaultFramework ("swap-qos" )
62
62
f .NamespacePodSecurityLevel = admissionapi .LevelBaseline
63
63
64
+ ginkgo .BeforeEach (func () {
65
+ gomega .Expect (isSwapFeatureGateEnabled ()).To (gomega .BeTrueBecause ("NodeSwap feature should be on" ))
66
+ })
67
+
64
68
f .Context (framework .WithNodeConformance (), func () {
69
+
65
70
ginkgo .DescribeTable ("with configuration" , func (qosClass v1.PodQOSClass , memoryRequestEqualLimit bool ) {
66
71
ginkgo .By (fmt .Sprintf ("Creating a pod of QOS class %s. memoryRequestEqualLimit: %t" , qosClass , memoryRequestEqualLimit ))
67
72
pod := getSwapTestPod (f , qosClass , memoryRequestEqualLimit )
68
73
pod = runPodAndWaitUntilScheduled (f , pod )
69
74
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" ))
73
76
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
+ }
79
85
80
- if ! isLimitedSwap {
81
- ginkgo .By ("expecting no swap" )
86
+ case types .NoSwap , "" :
82
87
expectNoSwap (pod )
83
- return
84
- }
85
88
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
+ }
89
92
},
90
93
ginkgo .Entry ("QOS Best-effort" , v1 .PodQOSBestEffort , false ),
91
94
ginkgo .Entry ("QOS Burstable" , v1 .PodQOSBurstable , false ),
@@ -432,18 +435,13 @@ func calcSwapForBurstablePod(f *framework.Framework, pod *v1.Pod) int64 {
432
435
return int64 (swapAllocation )
433
436
}
434
437
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 {
443
439
kubeletCfg , err := getCurrentKubeletConfig (context .Background ())
444
440
framework .ExpectNoError (err , "cannot get kubelet config" )
445
441
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
447
445
}
448
446
449
447
func cloneQuantity (resource * resource.Quantity ) * resource.Quantity {
0 commit comments