@@ -40,8 +40,10 @@ import (
40
40
utilfeature "k8s.io/apiserver/pkg/util/feature"
41
41
featuregatetesting "k8s.io/component-base/featuregate/testing"
42
42
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
43
+ "k8s.io/kubernetes/pkg/apis/scheduling"
43
44
"k8s.io/kubernetes/pkg/features"
44
45
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
46
+ "k8s.io/utils/ptr"
45
47
)
46
48
47
49
func makeExpectedConfig (m * kubeGenericRuntimeManager , pod * v1.Pod , containerIndex int , enforceMemoryQoS bool ) * runtimeapi.ContainerConfig {
@@ -1031,6 +1033,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
1031
1033
swapBehavior string
1032
1034
addContainerWithoutRequests bool
1033
1035
addGuaranteedContainer bool
1036
+ isCriticalPod bool
1034
1037
}{
1035
1038
// With cgroup v1
1036
1039
{
@@ -1208,6 +1211,16 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
1208
1211
addContainerWithoutRequests : true ,
1209
1212
addGuaranteedContainer : false ,
1210
1213
},
1214
+
1215
+ // When the pod is considered critical, disallow swap access
1216
+ {
1217
+ name : "Best-effort QoS, cgroups v2, LimitedSwap, critical pod" ,
1218
+ cgroupVersion : cgroupV2 ,
1219
+ qosClass : v1 .PodQOSBurstable ,
1220
+ nodeSwapFeatureGateEnabled : true ,
1221
+ swapBehavior : types .LimitedSwap ,
1222
+ isCriticalPod : true ,
1223
+ },
1211
1224
} {
1212
1225
t .Run (tc .name , func (t * testing.T ) {
1213
1226
setCgroupVersionDuringTest (tc .cgroupVersion )
@@ -1244,6 +1257,11 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
1244
1257
pod .Spec .Containers [0 ].Resources = resourceReqsC1
1245
1258
pod .Spec .Containers [1 ].Resources = resourceReqsC2
1246
1259
1260
+ if tc .isCriticalPod {
1261
+ pod .Spec .Priority = ptr .To (scheduling .SystemCriticalPriority )
1262
+ assert .True (t , types .IsCriticalPod (pod ), "pod is expected to be critical" )
1263
+ }
1264
+
1247
1265
resourcesC1 := m .generateLinuxContainerResources (pod , & pod .Spec .Containers [0 ], false )
1248
1266
resourcesC2 := m .generateLinuxContainerResources (pod , & pod .Spec .Containers [1 ], false )
1249
1267
@@ -1252,7 +1270,7 @@ func TestGenerateLinuxContainerResourcesWithSwap(t *testing.T) {
1252
1270
return
1253
1271
}
1254
1272
1255
- if ! tc .nodeSwapFeatureGateEnabled || tc .cgroupVersion == cgroupV1 || (tc .swapBehavior == types .LimitedSwap && tc .qosClass != v1 .PodQOSBurstable ) {
1273
+ if tc . isCriticalPod || ! tc .nodeSwapFeatureGateEnabled || tc .cgroupVersion == cgroupV1 || (tc .swapBehavior == types .LimitedSwap && tc .qosClass != v1 .PodQOSBurstable ) {
1256
1274
expectNoSwap (tc .cgroupVersion , resourcesC1 , resourcesC2 )
1257
1275
return
1258
1276
}
0 commit comments