diff --git a/plugin/pkg/scheduler/core/equivalence_cache.go b/plugin/pkg/scheduler/core/equivalence_cache.go index 28d12614b1f..d48f5a4ef83 100644 --- a/plugin/pkg/scheduler/core/equivalence_cache.go +++ b/plugin/pkg/scheduler/core/equivalence_cache.go @@ -51,7 +51,7 @@ func newAlgorithmCache() AlgorithmCache { } } -// Store a map of predicate cache with maxsize +// EquivalenceCache stores a map of predicate cache with maxsize type EquivalenceCache struct { sync.RWMutex getEquivalencePod algorithm.GetEquivalencePodFunc @@ -179,13 +179,14 @@ func (ec *EquivalenceCache) InvalidateCachedPredicateItemForPodAdd(pod *v1.Pod, } // getHashEquivalencePod returns the hash of equivalence pod. -// if no equivalence pod found, return 0 -func (ec *EquivalenceCache) getHashEquivalencePod(pod *v1.Pod) uint64 { +// 1. equivalenceHash +// 2. if equivalence pod is found +func (ec *EquivalenceCache) getHashEquivalencePod(pod *v1.Pod) (uint64, bool) { equivalencePod := ec.getEquivalencePod(pod) if equivalencePod != nil { hash := fnv.New32a() hashutil.DeepHashObject(hash, equivalencePod) - return uint64(hash.Sum32()) + return uint64(hash.Sum32()), true } - return 0 + return 0, false } diff --git a/plugin/pkg/scheduler/core/equivalence_cache_test.go b/plugin/pkg/scheduler/core/equivalence_cache_test.go index 5c069a89e1a..20f2ed6d238 100644 --- a/plugin/pkg/scheduler/core/equivalence_cache_test.go +++ b/plugin/pkg/scheduler/core/equivalence_cache_test.go @@ -287,9 +287,9 @@ func TestGetHashEquivalencePod(t *testing.T) { }, } - hash1 := ecache.getHashEquivalencePod(pod1) - hash2 := ecache.getHashEquivalencePod(pod2) - hash3 := ecache.getHashEquivalencePod(pod3) + hash1, _ := ecache.getHashEquivalencePod(pod1) + hash2, _ := ecache.getHashEquivalencePod(pod2) + hash3, _ := ecache.getHashEquivalencePod(pod3) if hash1 != hash2 { t.Errorf("Failed: pod %v and %v is expected to be equivalent", pod1.Name, pod2.Name) @@ -305,11 +305,10 @@ func TestGetHashEquivalencePod(t *testing.T) { Name: "pod4", }, } - hash4 := ecache.getHashEquivalencePod(pod4) - - if hash4 != 0 { - t.Errorf("Failed: equivalence hash of pod %v is expected to be: 0, but got: %v", - pod4.Name, hash4) + _, found := ecache.getHashEquivalencePod(pod4) + if found { + t.Errorf("Failed: equivalence hash of pod %v is not expected to be found, but got: %v", + pod4.Name, found) } } diff --git a/plugin/pkg/scheduler/core/generic_scheduler.go b/plugin/pkg/scheduler/core/generic_scheduler.go index a9244f6636e..eb5207f119a 100644 --- a/plugin/pkg/scheduler/core/generic_scheduler.go +++ b/plugin/pkg/scheduler/core/generic_scheduler.go @@ -245,8 +245,7 @@ func podFitsOnNode(pod *v1.Pod, meta interface{}, info *schedulercache.NodeInfo, ) if ecache != nil { // getHashEquivalencePod will return immediately if no equivalence pod found - equivalenceHash = ecache.getHashEquivalencePod(pod) - eCacheAvailable = (equivalenceHash != 0) + equivalenceHash, eCacheAvailable = ecache.getHashEquivalencePod(pod) } for predicateKey, predicate := range predicateFuncs { // If equivalenceCache is available