mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Simplify logic in podFitsOnNode.
Use new (*EquivalenceCache).RunPredicate to simplify how we read and update the equivalence cache items.
This commit is contained in:
parent
e67b3225a4
commit
55662f26f1
@ -508,39 +508,11 @@ func podFitsOnNode(
|
||||
)
|
||||
//TODO (yastij) : compute average predicate restrictiveness to export it as Prometheus metric
|
||||
if predicate, exist := predicateFuncs[predicateKey]; exist {
|
||||
// Use an in-line function to guarantee invocation of ecache.Unlock()
|
||||
// when the in-line function returns.
|
||||
func() {
|
||||
var invalid bool
|
||||
if eCacheAvailable {
|
||||
// Lock ecache here to avoid a race condition against cache invalidation invoked
|
||||
// in event handlers. This race has existed despite locks in equivClassCacheimplementation.
|
||||
ecache.Lock()
|
||||
defer ecache.Unlock()
|
||||
// PredicateWithECache will return its cached predicate results.
|
||||
fit, reasons, invalid = ecache.PredicateWithECache(
|
||||
pod.GetName(), info.Node().GetName(),
|
||||
predicateKey, equivCacheInfo.hash, false)
|
||||
}
|
||||
|
||||
if !eCacheAvailable || invalid {
|
||||
// we need to execute predicate functions since equivalence cache does not work
|
||||
fit, reasons, err = predicate(pod, metaToUse, nodeInfoToUse)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if eCacheAvailable {
|
||||
// Skip update if NodeInfo is stale.
|
||||
if cache != nil && cache.IsUpToDate(info) {
|
||||
ecache.UpdateCachedPredicateItem(
|
||||
pod.GetName(), info.Node().GetName(),
|
||||
predicateKey, fit, reasons, equivCacheInfo.hash, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if eCacheAvailable {
|
||||
fit, reasons, err = ecache.RunPredicate(predicate, predicateKey, pod, metaToUse, nodeInfoToUse, equivCacheInfo, cache)
|
||||
} else {
|
||||
fit, reasons, err = predicate(pod, metaToUse, nodeInfoToUse)
|
||||
}
|
||||
if err != nil {
|
||||
return false, []algorithm.PredicateFailureReason{}, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user