Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2616] Remove unused bool return from PreemptionPredicates() #841

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (ctx *Context) IsPodFitNodeViaPreemption(name, node string, allocations []s
}

// check predicates for a match
if index, _ := ctx.predManager.PreemptionPredicates(pod, targetNode, victims, startIndex); index != -1 {
if index := ctx.predManager.PreemptionPredicates(pod, targetNode, victims, startIndex); index != -1 {
return index, true
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/scheduler_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ func (m *mockPredicateManager) Predicates(_ *v1.Pod, _ *framework.NodeInfo, _ bo
return "", nil
}

func (m *mockPredicateManager) PreemptionPredicates(_ *v1.Pod, _ *framework.NodeInfo, _ []*v1.Pod, _ int) (index int, ok bool) {
return 0, true
func (m *mockPredicateManager) PreemptionPredicates(_ *v1.Pod, _ *framework.NodeInfo, _ []*v1.Pod, _ int) (index int) {
return 0
}

func initCallbackTest(t *testing.T, podAssigned, placeholder bool) (*AsyncRMCallback, *Context) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/plugin/predicates/predicate_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
type PredicateManager interface {
EventsToRegister(queueingHintFn framework.QueueingHintFn) []framework.ClusterEventWithHint
Predicates(pod *v1.Pod, node *framework.NodeInfo, allocate bool) (plugin string, error error)
PreemptionPredicates(pod *v1.Pod, node *framework.NodeInfo, victims []*v1.Pod, startIndex int) (index int, ok bool)
PreemptionPredicates(pod *v1.Pod, node *framework.NodeInfo, victims []*v1.Pod, startIndex int) (index int)
}

var _ PredicateManager = &predicateManagerImpl{}
Expand Down Expand Up @@ -125,7 +125,7 @@
return p.predicatesReserve(pod, node)
}

func (p *predicateManagerImpl) PreemptionPredicates(pod *v1.Pod, node *framework.NodeInfo, victims []*v1.Pod, startIndex int) (int, bool) {
func (p *predicateManagerImpl) PreemptionPredicates(pod *v1.Pod, node *framework.NodeInfo, victims []*v1.Pod, startIndex int) int {
ctx := context.Background()
state := framework.NewCycleState()

Expand All @@ -138,7 +138,7 @@
zap.String("plugin", plugin),
zap.String("message", s.Message()))

return -1, false
return -1

Check warning on line 141 in pkg/plugin/predicates/predicate_manager.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/predicates/predicate_manager.go#L141

Added line #L141 was not covered by tests
}

// clone node so that we can modify it here for predicate checks
Expand All @@ -154,15 +154,15 @@
p.removePodFromNodeNoFail(preemptingNode, victims[i])
status, _ := p.runFilterPlugins(ctx, *p.allocationFilters, state, pod, preemptingNode, skip)
if status.IsSuccess() {
return i, true
return i
}
}

// no fit, log and return
log.Log(log.ShimPredicates).Debug("Filter checks failed during preemption check, no fit",
zap.String("podUID", string(pod.UID)),
zap.String("nodeID", node.Node().Name))
return -1, false
return -1
}

func (p *predicateManagerImpl) removePodFromNodeNoFail(node *framework.NodeInfo, pod *v1.Pod) {
Expand Down
15 changes: 6 additions & 9 deletions pkg/plugin/predicates/predicate_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ func TestPreemptionPredicatesEmpty(t *testing.T) {
node := framework.NewNodeInfo()
node.SetNode(&v1.Node{})
victims := make([]*v1.Pod, 0)
index, ok := predicateManager.PreemptionPredicates(pod, node, victims, 0)
assert.Check(t, !ok, "check should have failed")
assert.Equal(t, index, -1, "wrong index")
index := predicateManager.PreemptionPredicates(pod, node, victims, 0)
assert.Equal(t, index, -1, "should not find any victim index after preemption check")
}
chenyulin0719 marked this conversation as resolved.
Show resolved Hide resolved

func TestPreemptionPredicates(t *testing.T) {
Expand Down Expand Up @@ -115,18 +114,16 @@ func TestPreemptionPredicates(t *testing.T) {
node.AddPod(victims[3])

// all but 1 existing pod should need removing
index, ok := predicateManager.PreemptionPredicates(pod, node, victims, 1)
assert.Check(t, ok, "check failed")
assert.Equal(t, index, 2, "wrong index")
index := predicateManager.PreemptionPredicates(pod, node, victims, 1)
assert.Equal(t, index, 2, "wrong victim index")

// try again, but with too many resources requested
pod = newResourcePod(framework.Resource{MilliCPU: 1500, Memory: 15000000})
pod.Name = "largepod"
pod.UID = "largepod"

index, ok = predicateManager.PreemptionPredicates(pod, node, victims, 1)
assert.Check(t, !ok, "check should have failed")
assert.Equal(t, index, -1, "wrong index")
index = predicateManager.PreemptionPredicates(pod, node, victims, 1)
assert.Equal(t, index, -1, "should not find any victim index after preemption check")
}

func TestEventsToRegister(t *testing.T) {
Expand Down