mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	unit tests: exclude critical pods from swapping
Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
		@@ -40,8 +40,10 @@ import (
 | 
			
		||||
	utilfeature "k8s.io/apiserver/pkg/util/feature"
 | 
			
		||||
	featuregatetesting "k8s.io/component-base/featuregate/testing"
 | 
			
		||||
	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/apis/scheduling"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/features"
 | 
			
		||||
	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
 | 
			
		||||
	"k8s.io/utils/ptr"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func makeExpectedConfig(m *kubeGenericRuntimeManager, pod *v1.Pod, containerIndex int, enforceMemoryQoS bool) *runtimeapi.ContainerConfig {
 | 
			
		||||
@@ -1031,6 +1033,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
 | 
			
		||||
		swapBehavior                string
 | 
			
		||||
		addContainerWithoutRequests bool
 | 
			
		||||
		addGuaranteedContainer      bool
 | 
			
		||||
		isCriticalPod               bool
 | 
			
		||||
	}{
 | 
			
		||||
		// With cgroup v1
 | 
			
		||||
		{
 | 
			
		||||
@@ -1208,6 +1211,16 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
 | 
			
		||||
			addContainerWithoutRequests: true,
 | 
			
		||||
			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) {
 | 
			
		||||
			setCgroupVersionDuringTest(tc.cgroupVersion)
 | 
			
		||||
@@ -1244,6 +1257,11 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
 | 
			
		||||
			pod.Spec.Containers[0].Resources = resourceReqsC1
 | 
			
		||||
			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)
 | 
			
		||||
			resourcesC2 := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[1], false)
 | 
			
		||||
 | 
			
		||||
@@ -1252,7 +1270,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
 | 
			
		||||
				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)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user