mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #49616 from sakeven/feature/found_HashEquivalencePod
Automatic merge from submit-queue (batch tested with PRs 51480, 49616, 50123, 50846, 50404) getHashEquivalencePod should return if equivalence pod is found Signed-off-by: sakeven <jc5930@sina.cn> **What this PR does / why we need it**: getHashEquivalencePod should return if equivalence pod is found, rather than simply check equivalenceHash equals to 0 later. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ``` NONE ```
This commit is contained in:
commit
a8a505b767
@ -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 {
|
type EquivalenceCache struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
getEquivalencePod algorithm.GetEquivalencePodFunc
|
getEquivalencePod algorithm.GetEquivalencePodFunc
|
||||||
@ -179,13 +179,14 @@ func (ec *EquivalenceCache) InvalidateCachedPredicateItemForPodAdd(pod *v1.Pod,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getHashEquivalencePod returns the hash of equivalence pod.
|
// getHashEquivalencePod returns the hash of equivalence pod.
|
||||||
// if no equivalence pod found, return 0
|
// 1. equivalenceHash
|
||||||
func (ec *EquivalenceCache) getHashEquivalencePod(pod *v1.Pod) uint64 {
|
// 2. if equivalence pod is found
|
||||||
|
func (ec *EquivalenceCache) getHashEquivalencePod(pod *v1.Pod) (uint64, bool) {
|
||||||
equivalencePod := ec.getEquivalencePod(pod)
|
equivalencePod := ec.getEquivalencePod(pod)
|
||||||
if equivalencePod != nil {
|
if equivalencePod != nil {
|
||||||
hash := fnv.New32a()
|
hash := fnv.New32a()
|
||||||
hashutil.DeepHashObject(hash, equivalencePod)
|
hashutil.DeepHashObject(hash, equivalencePod)
|
||||||
return uint64(hash.Sum32())
|
return uint64(hash.Sum32()), true
|
||||||
}
|
}
|
||||||
return 0
|
return 0, false
|
||||||
}
|
}
|
||||||
|
@ -287,9 +287,9 @@ func TestGetHashEquivalencePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
hash1 := ecache.getHashEquivalencePod(pod1)
|
hash1, _ := ecache.getHashEquivalencePod(pod1)
|
||||||
hash2 := ecache.getHashEquivalencePod(pod2)
|
hash2, _ := ecache.getHashEquivalencePod(pod2)
|
||||||
hash3 := ecache.getHashEquivalencePod(pod3)
|
hash3, _ := ecache.getHashEquivalencePod(pod3)
|
||||||
|
|
||||||
if hash1 != hash2 {
|
if hash1 != hash2 {
|
||||||
t.Errorf("Failed: pod %v and %v is expected to be equivalent", pod1.Name, pod2.Name)
|
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",
|
Name: "pod4",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
hash4 := ecache.getHashEquivalencePod(pod4)
|
_, found := ecache.getHashEquivalencePod(pod4)
|
||||||
|
if found {
|
||||||
if hash4 != 0 {
|
t.Errorf("Failed: equivalence hash of pod %v is not expected to be found, but got: %v",
|
||||||
t.Errorf("Failed: equivalence hash of pod %v is expected to be: 0, but got: %v",
|
pod4.Name, found)
|
||||||
pod4.Name, hash4)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,8 +245,7 @@ func podFitsOnNode(pod *v1.Pod, meta interface{}, info *schedulercache.NodeInfo,
|
|||||||
)
|
)
|
||||||
if ecache != nil {
|
if ecache != nil {
|
||||||
// getHashEquivalencePod will return immediately if no equivalence pod found
|
// getHashEquivalencePod will return immediately if no equivalence pod found
|
||||||
equivalenceHash = ecache.getHashEquivalencePod(pod)
|
equivalenceHash, eCacheAvailable = ecache.getHashEquivalencePod(pod)
|
||||||
eCacheAvailable = (equivalenceHash != 0)
|
|
||||||
}
|
}
|
||||||
for predicateKey, predicate := range predicateFuncs {
|
for predicateKey, predicate := range predicateFuncs {
|
||||||
// If equivalenceCache is available
|
// If equivalenceCache is available
|
||||||
|
Loading…
Reference in New Issue
Block a user