This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new 29981633 [YUNIKORN-2575] Clarify error returned by IsPodFitNode (#824)
29981633 is described below
commit 299816338caa1053e76e8f0d627321335d159cd2
Author: Wilfred Spiegelenburg <[email protected]>
AuthorDate: Wed Apr 24 10:42:01 2024 +1000
[YUNIKORN-2575] Clarify error returned by IsPodFitNode (#824)
IsPodFitNode should clearly set the error if the pod or node is missing
from the cache when run. The result, if it is an error, contains the
predicate plugin name that failed to improve identification in the
events.
Closes: #824
Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
pkg/cache/context.go | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/pkg/cache/context.go b/pkg/cache/context.go
index c805f0ba..6c9f34e2 100644
--- a/pkg/cache/context.go
+++ b/pkg/cache/context.go
@@ -21,6 +21,7 @@ package cache
import (
"context"
"encoding/json"
+ "errors"
"fmt"
"sort"
"strconv"
@@ -56,6 +57,11 @@ import (
const registerNodeContextHandler = "RegisterNodeContextHandler"
+var (
+ ErrorPodNotFound = errors.New("predicates were not run because pod was
not found in cache")
+ ErrorNodeNotFound = errors.New("predicates were not run because node
was not found in cache")
+)
+
// context maintains scheduling state, like apps and apps' tasks.
type Context struct {
applications map[string]*Application // apps
@@ -633,21 +639,28 @@ func (ctx *Context) EventsToRegister(queueingHintFn
framework.QueueingHintFn) []
return ctx.predManager.EventsToRegister(queueingHintFn)
}
-// evaluate given predicates based on current context
+// IsPodFitNode evaluates given predicates based on current context
func (ctx *Context) IsPodFitNode(name, node string, allocate bool) error {
ctx.lock.RLock()
defer ctx.lock.RUnlock()
- if pod, ok := ctx.schedulerCache.GetPod(name); ok {
- // if pod exists in cache, try to run predicates
- if targetNode := ctx.schedulerCache.GetNode(node); targetNode
!= nil {
- // need to lock cache here as predicates need a stable
view into the cache
- ctx.schedulerCache.LockForReads()
- defer ctx.schedulerCache.UnlockForReads()
- _, err := ctx.predManager.Predicates(pod, targetNode,
allocate)
- return err
- }
+ var pod *v1.Pod
+ var ok bool
+ if pod, ok = ctx.schedulerCache.GetPod(name); !ok {
+ return ErrorPodNotFound
+ }
+ // if pod exists in cache, try to run predicates
+ targetNode := ctx.schedulerCache.GetNode(node)
+ if targetNode == nil {
+ return ErrorNodeNotFound
+ }
+ // need to lock cache here as predicates need a stable view into the
cache
+ ctx.schedulerCache.LockForReads()
+ defer ctx.schedulerCache.UnlockForReads()
+ plugin, err := ctx.predManager.Predicates(pod, targetNode, allocate)
+ if err != nil {
+ err = errors.Join(fmt.Errorf("failed plugin: '%s'", plugin),
err)
}
- return fmt.Errorf("predicates were not running because pod or node was
not found in cache")
+ return err
}
func (ctx *Context) IsPodFitNodeViaPreemption(name, node string, allocations
[]string, startIndex int) (index int, ok bool) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]