Skip to content

Commit

Permalink
[YUNIKORN-2577] Remove named returns from IsPodFitNodeViaPreemption (a…
Browse files Browse the repository at this point in the history
…pache#826)

Closes: apache#826

Signed-off-by: Chia-Ping Tsai <[email protected]>
  • Loading branch information
ryankert01 authored and chia7712 committed May 9, 2024
1 parent 04d951e commit 1e4bcc0
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,35 +664,31 @@ 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
ctx.schedulerCache.LockForReads()
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
}
}
}
Expand Down

0 comments on commit 1e4bcc0

Please sign in to comment.