From 467cde3072d8a7cd85463e54c9c4a39087e5e30e Mon Sep 17 00:00:00 2001 From: lili Date: Thu, 23 Nov 2023 20:58:27 +0800 Subject: [PATCH] skip 'pods' resource when checking if the Resource is empty Signed-off-by: lili --- pkg/scheduler/api/resource_info.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/api/resource_info.go b/pkg/scheduler/api/resource_info.go index d732fafcaaf..e1f9220e525 100644 --- a/pkg/scheduler/api/resource_info.go +++ b/pkg/scheduler/api/resource_info.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" v1helper "k8s.io/kubernetes/pkg/scheduler/util" @@ -193,13 +194,24 @@ func (r *Resource) Get(rn v1.ResourceName) float64 { } } +// Skip checking "pods" resource. +// All pods request one "pods" resource now, no need to check it +var emptyCheckIgnoredScalarResources = sets.NewString("pods") + +func IsEmptyCheckIgnoredScalarResource(name v1.ResourceName) bool { + return emptyCheckIgnoredScalarResources.Has(string(name)) +} + // IsEmpty returns false if any kind of resource is not less than min value, otherwise returns true func (r *Resource) IsEmpty() bool { if !(r.MilliCPU < minResource && r.Memory < minResource) { return false } - for _, rQuant := range r.ScalarResources { + for rName, rQuant := range r.ScalarResources { + if IsEmptyCheckIgnoredScalarResource(rName) { + continue + } if rQuant >= minResource { return false }