mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +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
|
//TODO (yastij) : compute average predicate restrictiveness to export it as Prometheus metric
|
||||||
if predicate, exist := predicateFuncs[predicateKey]; exist {
|
if predicate, exist := predicateFuncs[predicateKey]; exist {
|
||||||
// Use an in-line function to guarantee invocation of ecache.Unlock()
|
if eCacheAvailable {
|
||||||
// when the in-line function returns.
|
fit, reasons, err = ecache.RunPredicate(predicate, predicateKey, pod, metaToUse, nodeInfoToUse, equivCacheInfo, cache)
|
||||||
func() {
|
} else {
|
||||||
var invalid bool
|
fit, reasons, err = predicate(pod, metaToUse, nodeInfoToUse)
|
||||||
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 err != nil {
|
if err != nil {
|
||||||
return false, []algorithm.PredicateFailureReason{}, err
|
return false, []algorithm.PredicateFailureReason{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user