Skip to content

Commit

Permalink
scheduler: enhance deviceshare error message for reservation
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed May 23, 2024
1 parent 7708b19 commit 52dcaa4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/deviceshare/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ func Test_Plugin_FilterReservation(t *testing.T) {
assert.True(t, status.IsSuccess())

status = pl.FilterReservation(context.TODO(), cycleState, pod, reservationInfo, "test-node-1")
assert.Equal(t, framework.NewStatus(framework.Unschedulable, "node(s) no reservation(s) to meet the device requirements"), status)
assert.Equal(t, framework.NewStatus(framework.Unschedulable, "Insufficient gpu devices by reservation"), status)
}

func Test_Plugin_Reserve(t *testing.T) {
Expand Down
15 changes: 14 additions & 1 deletion pkg/scheduler/plugins/deviceshare/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (p *Plugin) tryAllocateFromReservation(

basicPreemptible = appendAllocated(nil, basicPreemptible, restoreState.mergedMatchedAllocated)

var reservationReasons []*framework.Status
for _, alloc := range matchedReservations {
rInfo := alloc.rInfo
preemptibleInRR := state.preemptibleInRRs[node.Name][rInfo.UID()]
Expand All @@ -222,6 +223,7 @@ func (p *Plugin) tryAllocateFromReservation(
hasSatisfiedReservation = true
break
}
reservationReasons = append(reservationReasons, status)
} else if allocatePolicy == schedulingv1alpha1.ReservationAllocatePolicyRestricted {
_, status := allocator.Allocate(preferred, preferred, nil, preemptible)
if status.IsSuccess() {
Expand All @@ -236,15 +238,26 @@ func (p *Plugin) tryAllocateFromReservation(
hasSatisfiedReservation = true
break
}
reservationReasons = append(reservationReasons, status)
}
}
}
if !hasSatisfiedReservation && requiredFromReservation {
return nil, framework.NewStatus(framework.Unschedulable, "node(s) no reservation(s) to meet the device requirements")
return nil, framework.NewStatus(framework.Unschedulable, p.makePostFilterReasons(reservationReasons)...)
}
return result, nil
}

func (p *Plugin) makePostFilterReasons(reservationReasons []*framework.Status) []string {
var reasons []string
for _, status := range reservationReasons {
for _, r := range status.Reasons() {
reasons = append(reasons, fmt.Sprintf("%s by reservation", r))
}
}
return reasons
}

// scoreWithReservation combine the reservation with the node's resource usage to calculate the reservation score.
func (p *Plugin) scoreWithReservation(
allocator *AutopilotAllocator,
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/plugins/deviceshare/reservation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func Test_tryAllocateFromReservation(t *testing.T) {
},
requiredFromReservation: true,
wantResult: nil,
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) no reservation(s) to meet the device requirements"),
wantStatus: framework.NewStatus(framework.Unschedulable, "Insufficient gpu devices by reservation"),
},
{
name: "failed to allocate from Aligned policy reservation that remaining little not fits request",
Expand Down Expand Up @@ -566,7 +566,7 @@ func Test_tryAllocateFromReservation(t *testing.T) {
},
requiredFromReservation: true,
wantResult: nil,
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) no reservation(s) to meet the device requirements"),
wantStatus: framework.NewStatus(framework.Unschedulable, "Insufficient gpu devices by reservation"),
},
{
name: "allocate from Restricted policy reservation",
Expand Down Expand Up @@ -650,7 +650,7 @@ func Test_tryAllocateFromReservation(t *testing.T) {
},
requiredFromReservation: true,
wantResult: nil,
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) no reservation(s) to meet the device requirements"),
wantStatus: framework.NewStatus(framework.Unschedulable, "Insufficient gpu devices by reservation"),
},
}

Expand Down

0 comments on commit 52dcaa4

Please sign in to comment.