Skip to content

Commit

Permalink
fix some reservationAffinity related error (#2072)
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <[email protected]>
Co-authored-by: wangjianyu.wjy <[email protected]>
  • Loading branch information
ZiMengSheng and wangjianyu.wjy authored May 29, 2024
1 parent 0eac242 commit a685498
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/deviceshare/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ func (p *Plugin) tryAllocateFromReservation(
hasSatisfiedReservation = true
break
}
reservationReasons = append(reservationReasons, status)
}
reservationReasons = append(reservationReasons, status)
}
}
if !hasSatisfiedReservation && requiredFromReservation {
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/deviceshare/topology_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *Plugin) Allocate(ctx context.Context, cycleState *framework.CycleState,

nodeDeviceInfo.lock.RLock()
defer nodeDeviceInfo.lock.RUnlock()
allocateResult, status := p.tryAllocateFromReservation(allocator, state, restoreState, restoreState.matched, node, preemptible, false)
allocateResult, status := p.tryAllocateFromReservation(allocator, state, restoreState, restoreState.matched, node, preemptible, state.hasReservationAffinity)
if !status.IsSuccess() {
return status
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (p *Plugin) generateTopologyHints(cycleState *framework.CycleState, state *
}
}

allocateResult, status := p.tryAllocateFromReservation(allocator, state, restoreState, restoreState.matched, node, preemptible, false)
allocateResult, status := p.tryAllocateFromReservation(allocator, state, restoreState, restoreState.matched, node, preemptible, state.hasReservationAffinity)
if !status.IsSuccess() {
return
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/scheduler/plugins/reservation/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ func (pl *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
return nil
}

state := getStateData(cycleState)
nominatedReservation := pl.handle.GetReservationNominator().GetNominatedReservation(pod, nodeName)
if nominatedReservation == nil {
// The scheduleOne skip scores and reservation nomination if there is only one node available.
Expand All @@ -598,6 +599,9 @@ func (pl *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
return status
}
if nominatedReservation == nil {
if state.hasAffinity {
return framework.NewStatus(framework.Unschedulable, ErrReasonReservationAffinity)
}
klog.V(5).Infof("Skip reserve with reservation since there are no matched reservations, pod %v, node: %v", klog.KObj(pod), nodeName)
return nil
}
Expand All @@ -609,8 +613,6 @@ func (pl *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
klog.ErrorS(err, "Failed to assume pod in reservationCache", "pod", klog.KObj(pod), "reservation", klog.KObj(nominatedReservation))
return framework.AsStatus(err)
}

state := getStateData(cycleState)
state.assumed = nominatedReservation.Clone()
klog.V(4).InfoS("Reserve pod to node with reservations", "pod", klog.KObj(pod), "node", nodeName, "assumed", klog.KObj(nominatedReservation))
return nil
Expand Down Expand Up @@ -647,6 +649,9 @@ func (pl *Plugin) PreBind(ctx context.Context, cycleState *framework.CycleState,

state := getStateData(cycleState)
if state.assumed == nil {
if state.hasAffinity {
return framework.NewStatus(framework.Unschedulable, ErrReasonReservationAffinity)
}
klog.V(5).Infof("Skip the Reservation PreBind since no reservation allocated for the pod %s on node %s", klog.KObj(pod), nodeName)
return nil
}
Expand Down

0 comments on commit a685498

Please sign in to comment.