mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
unit tests: exclude critical pods from swapping
Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
parent
532cd5f84c
commit
6c1f14c468
@ -40,8 +40,10 @@ import (
|
|||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeExpectedConfig(m *kubeGenericRuntimeManager, pod *v1.Pod, containerIndex int, enforceMemoryQoS bool) *runtimeapi.ContainerConfig {
|
func makeExpectedConfig(m *kubeGenericRuntimeManager, pod *v1.Pod, containerIndex int, enforceMemoryQoS bool) *runtimeapi.ContainerConfig {
|
||||||
@ -1031,6 +1033,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
|
|||||||
swapBehavior string
|
swapBehavior string
|
||||||
addContainerWithoutRequests bool
|
addContainerWithoutRequests bool
|
||||||
addGuaranteedContainer bool
|
addGuaranteedContainer bool
|
||||||
|
isCriticalPod bool
|
||||||
}{
|
}{
|
||||||
// With cgroup v1
|
// With cgroup v1
|
||||||
{
|
{
|
||||||
@ -1208,6 +1211,16 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
|
|||||||
addContainerWithoutRequests: true,
|
addContainerWithoutRequests: true,
|
||||||
addGuaranteedContainer: false,
|
addGuaranteedContainer: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// When the pod is considered critical, disallow swap access
|
||||||
|
{
|
||||||
|
name: "Best-effort QoS, cgroups v2, LimitedSwap, critical pod",
|
||||||
|
cgroupVersion: cgroupV2,
|
||||||
|
qosClass: v1.PodQOSBurstable,
|
||||||
|
nodeSwapFeatureGateEnabled: true,
|
||||||
|
swapBehavior: types.LimitedSwap,
|
||||||
|
isCriticalPod: true,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
setCgroupVersionDuringTest(tc.cgroupVersion)
|
setCgroupVersionDuringTest(tc.cgroupVersion)
|
||||||
@ -1244,6 +1257,11 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
|
|||||||
pod.Spec.Containers[0].Resources = resourceReqsC1
|
pod.Spec.Containers[0].Resources = resourceReqsC1
|
||||||
pod.Spec.Containers[1].Resources = resourceReqsC2
|
pod.Spec.Containers[1].Resources = resourceReqsC2
|
||||||
|
|
||||||
|
if tc.isCriticalPod {
|
||||||
|
pod.Spec.Priority = ptr.To(scheduling.SystemCriticalPriority)
|
||||||
|
assert.True(t, types.IsCriticalPod(pod), "pod is expected to be critical")
|
||||||
|
}
|
||||||
|
|
||||||
resourcesC1 := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[0], false)
|
resourcesC1 := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[0], false)
|
||||||
resourcesC2 := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[1], false)
|
resourcesC2 := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[1], false)
|
||||||
|
|
||||||
@ -1252,7 +1270,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tc.nodeSwapFeatureGateEnabled || tc.cgroupVersion == cgroupV1 || (tc.swapBehavior == types.LimitedSwap && tc.qosClass != v1.PodQOSBurstable) {
|
if tc.isCriticalPod || !tc.nodeSwapFeatureGateEnabled || tc.cgroupVersion == cgroupV1 || (tc.swapBehavior == types.LimitedSwap && tc.qosClass != v1.PodQOSBurstable) {
|
||||||
expectNoSwap(tc.cgroupVersion, resourcesC1, resourcesC2)
|
expectNoSwap(tc.cgroupVersion, resourcesC1, resourcesC2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user