This is an automated email from the ASF dual-hosted git repository.
chia7712 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 1e4bcc09 [YUNIKORN-2577] Remove named returns from
IsPodFitNodeViaPreemption (#826)
1e4bcc09 is described below
commit 1e4bcc09794cf086b4fbee6d0c2c5d87756c62b7
Author: Ryan <[email protected]>
AuthorDate: Thu May 9 12:23:30 2024 +0800
[YUNIKORN-2577] Remove named returns from IsPodFitNodeViaPreemption (#826)
Closes: #826
Signed-off-by: Chia-Ping Tsai <[email protected]>
---
pkg/cache/context.go | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/pkg/cache/context.go b/pkg/cache/context.go
index 96493578..86f5661f 100644
--- a/pkg/cache/context.go
+++ b/pkg/cache/context.go
@@ -664,15 +664,15 @@ func (ctx *Context) IsPodFitNode(name, node string,
allocate bool) error {
return err
}
-func (ctx *Context) IsPodFitNodeViaPreemption(name, node string, allocations
[]string, startIndex int) (index int, ok bool) {
+func (ctx *Context) IsPodFitNodeViaPreemption(name, node string, allocations
[]string, startIndex int) (int, bool) {
// assume minimal pods need killing if running in testing mode
if ctx.apiProvider.IsTestingMode() {
- return startIndex, ok
+ return startIndex, false
}
ctx.lock.RLock()
defer ctx.lock.RUnlock()
- if pod, ok := ctx.schedulerCache.GetPod(name); ok {
+ if pod, _ := ctx.schedulerCache.GetPod(name); pod != nil {
// 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
@@ -680,19 +680,15 @@ func (ctx *Context) IsPodFitNodeViaPreemption(name, node
string, allocations []s
defer ctx.schedulerCache.UnlockForReads()
// look up each victim in the scheduler cache
- victims := make([]*v1.Pod, 0)
- for _, uid := range allocations {
- if victim, ok :=
ctx.schedulerCache.GetPodNoLock(uid); ok {
- victims = append(victims, victim)
- } else {
- // if pod isn't found, add a
placeholder so that the list is still the same size
- victims = append(victims, nil)
- }
+ victims := make([]*v1.Pod, len(allocations))
+ for index, uid := range allocations {
+ victim, _ :=
ctx.schedulerCache.GetPodNoLock(uid)
+ victims[index] = victim
}
// check predicates for a match
- if index, ok :=
ctx.predManager.PreemptionPredicates(pod, targetNode, victims, startIndex); ok {
- return index, ok
+ if index, _ :=
ctx.predManager.PreemptionPredicates(pod, targetNode, victims, startIndex);
index != -1 {
+ return index, true
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]