mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Update node conformance to use NoSwap
Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
parent
bdeb80a846
commit
b17050927c
@ -61,31 +61,34 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", nodefeature.Swap, func() {
|
|||||||
f := framework.NewDefaultFramework("swap-qos")
|
f := framework.NewDefaultFramework("swap-qos")
|
||||||
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
|
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
|
||||||
|
|
||||||
|
ginkgo.BeforeEach(func() {
|
||||||
|
gomega.Expect(isSwapFeatureGateEnabled()).To(gomega.BeTrueBecause("NodeSwap feature should be on"))
|
||||||
|
})
|
||||||
|
|
||||||
f.Context(framework.WithNodeConformance(), func() {
|
f.Context(framework.WithNodeConformance(), func() {
|
||||||
|
|
||||||
ginkgo.DescribeTable("with configuration", func(qosClass v1.PodQOSClass, memoryRequestEqualLimit bool) {
|
ginkgo.DescribeTable("with configuration", func(qosClass v1.PodQOSClass, memoryRequestEqualLimit bool) {
|
||||||
ginkgo.By(fmt.Sprintf("Creating a pod of QOS class %s. memoryRequestEqualLimit: %t", qosClass, memoryRequestEqualLimit))
|
ginkgo.By(fmt.Sprintf("Creating a pod of QOS class %s. memoryRequestEqualLimit: %t", qosClass, memoryRequestEqualLimit))
|
||||||
pod := getSwapTestPod(f, qosClass, memoryRequestEqualLimit)
|
pod := getSwapTestPod(f, qosClass, memoryRequestEqualLimit)
|
||||||
pod = runPodAndWaitUntilScheduled(f, pod)
|
pod = runPodAndWaitUntilScheduled(f, pod)
|
||||||
|
|
||||||
isCgroupV2 := isPodCgroupV2(f, pod)
|
gomega.Expect(isPodCgroupV2(f, pod)).To(gomega.BeTrueBecause("cgroup v2 is required for swap"))
|
||||||
isLimitedSwap := isLimitedSwap(f, pod)
|
|
||||||
isNoSwap := isNoSwap(f, pod)
|
|
||||||
|
|
||||||
if !isSwapFeatureGateEnabled() || !isCgroupV2 || isNoSwap || (isLimitedSwap && (qosClass != v1.PodQOSBurstable || memoryRequestEqualLimit)) {
|
switch swapBehavior := getSwapBehavior(); swapBehavior {
|
||||||
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))
|
case types.LimitedSwap:
|
||||||
|
if qosClass != v1.PodQOSBurstable || memoryRequestEqualLimit {
|
||||||
|
expectNoSwap(pod)
|
||||||
|
} else {
|
||||||
|
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
|
||||||
|
expectLimitedSwap(pod, expectedSwapLimit)
|
||||||
|
}
|
||||||
|
|
||||||
|
case types.NoSwap, "":
|
||||||
expectNoSwap(pod)
|
expectNoSwap(pod)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isLimitedSwap {
|
default:
|
||||||
ginkgo.By("expecting no swap")
|
gomega.Expect(swapBehavior).To(gomega.Or(gomega.Equal(types.LimitedSwap), gomega.Equal(types.NoSwap)), "unknown swap behavior")
|
||||||
expectNoSwap(pod)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("expecting limited swap")
|
|
||||||
expectedSwapLimit := calcSwapForBurstablePod(f, pod)
|
|
||||||
expectLimitedSwap(pod, expectedSwapLimit)
|
|
||||||
},
|
},
|
||||||
ginkgo.Entry("QOS Best-effort", v1.PodQOSBestEffort, false),
|
ginkgo.Entry("QOS Best-effort", v1.PodQOSBestEffort, false),
|
||||||
ginkgo.Entry("QOS Burstable", v1.PodQOSBurstable, false),
|
ginkgo.Entry("QOS Burstable", v1.PodQOSBurstable, false),
|
||||||
@ -432,18 +435,13 @@ func calcSwapForBurstablePod(f *framework.Framework, pod *v1.Pod) int64 {
|
|||||||
return int64(swapAllocation)
|
return int64(swapAllocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLimitedSwap(f *framework.Framework, pod *v1.Pod) bool {
|
func getSwapBehavior() string {
|
||||||
kubeletCfg, err := getCurrentKubeletConfig(context.Background())
|
kubeletCfg, err := getCurrentKubeletConfig(context.Background())
|
||||||
framework.ExpectNoError(err, "cannot get kubelet config")
|
framework.ExpectNoError(err, "cannot get kubelet config")
|
||||||
|
|
||||||
return kubeletCfg.MemorySwap.SwapBehavior == types.LimitedSwap
|
swapBehavior := kubeletCfg.MemorySwap.SwapBehavior
|
||||||
}
|
ginkgo.By("Figuring out swap behavior: " + swapBehavior)
|
||||||
|
return swapBehavior
|
||||||
func isNoSwap(f *framework.Framework, pod *v1.Pod) bool {
|
|
||||||
kubeletCfg, err := getCurrentKubeletConfig(context.Background())
|
|
||||||
framework.ExpectNoError(err, "cannot get kubelet config")
|
|
||||||
|
|
||||||
return kubeletCfg.MemorySwap.SwapBehavior == types.NoSwap || kubeletCfg.MemorySwap.SwapBehavior == ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneQuantity(resource *resource.Quantity) *resource.Quantity {
|
func cloneQuantity(resource *resource.Quantity) *resource.Quantity {
|
||||||
|
Loading…
Reference in New Issue
Block a user