skip pod resource check when request is zero

Signed-off-by: forrestchen <forrestchen@tencent.com>
This commit is contained in:
forrestchen 2023-03-09 17:05:11 +08:00
parent f5ddaa152e
commit bbf2b968c8
2 changed files with 15 additions and 3 deletions

View File

@ -276,7 +276,7 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor
return insufficientResources
}
if podRequest.MilliCPU > (nodeInfo.Allocatable.MilliCPU - nodeInfo.Requested.MilliCPU) {
if podRequest.MilliCPU > 0 && podRequest.MilliCPU > (nodeInfo.Allocatable.MilliCPU-nodeInfo.Requested.MilliCPU) {
insufficientResources = append(insufficientResources, InsufficientResource{
ResourceName: v1.ResourceCPU,
Reason: "Insufficient cpu",
@ -285,7 +285,7 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor
Capacity: nodeInfo.Allocatable.MilliCPU,
})
}
if podRequest.Memory > (nodeInfo.Allocatable.Memory - nodeInfo.Requested.Memory) {
if podRequest.Memory > 0 && podRequest.Memory > (nodeInfo.Allocatable.Memory-nodeInfo.Requested.Memory) {
insufficientResources = append(insufficientResources, InsufficientResource{
ResourceName: v1.ResourceMemory,
Reason: "Insufficient memory",
@ -294,7 +294,8 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor
Capacity: nodeInfo.Allocatable.Memory,
})
}
if podRequest.EphemeralStorage > (nodeInfo.Allocatable.EphemeralStorage - nodeInfo.Requested.EphemeralStorage) {
if podRequest.EphemeralStorage > 0 &&
podRequest.EphemeralStorage > (nodeInfo.Allocatable.EphemeralStorage-nodeInfo.Requested.EphemeralStorage) {
insufficientResources = append(insufficientResources, InsufficientResource{
ResourceName: v1.ResourceEphemeralStorage,
Reason: "Insufficient ephemeral-storage",

View File

@ -473,6 +473,17 @@ func TestEnoughRequests(t *testing.T) {
name: "skip checking extended resource request with quantity zero via resource groups",
wantInsufficientResources: []InsufficientResource{},
},
{
pod: newResourcePod(
framework.Resource{
ScalarResources: map[v1.ResourceName]int64{
extendedResourceA: 1,
}}),
nodeInfo: framework.NewNodeInfo(newResourcePod(framework.Resource{
MilliCPU: 20, Memory: 30, ScalarResources: map[v1.ResourceName]int64{extendedResourceA: 1}})),
name: "skip checking resource request with quantity zero",
wantInsufficientResources: []InsufficientResource{},
},
}
for _, test := range enoughPodsTests {