mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
scheduler: remove error param from doSchedule func
doSchedule currently accepts err values from previous invocation delegating error handling in a location different from the caller which can be hard to debug and is not a good practice. We still maintain the same invariants after the refactoring. If an err happened in a previous invocation to Register, the returned task object was nil causing task.AcceptedOffer() to return false. By not invoking doSchedule in case of an error we can eliminate the first `err == nil` check in doScheduler.
This commit is contained in:
parent
9bbfc35fa9
commit
0ad0c1f2b1
@ -278,7 +278,11 @@ func (k *kubeScheduler) Schedule(pod *api.Pod, unused algorithm.NodeLister) (str
|
|||||||
log.Infof("aborting Schedule, pod has been deleted %+v", pod)
|
log.Infof("aborting Schedule, pod has been deleted %+v", pod)
|
||||||
return "", noSuchPodErr
|
return "", noSuchPodErr
|
||||||
}
|
}
|
||||||
return k.doSchedule(k.api.tasks().Register(k.api.createPodTask(ctx, pod)))
|
task, err := k.api.tasks().Register(k.api.createPodTask(ctx, pod))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return k.doSchedule(task)
|
||||||
|
|
||||||
//TODO(jdef) it's possible that the pod state has diverged from what
|
//TODO(jdef) it's possible that the pod state has diverged from what
|
||||||
//we knew previously, we should probably update the task.Pod state here
|
//we knew previously, we should probably update the task.Pod state here
|
||||||
@ -294,7 +298,7 @@ func (k *kubeScheduler) Schedule(pod *api.Pod, unused algorithm.NodeLister) (str
|
|||||||
// but we're going to let someone else handle it, probably the mesos task error handler
|
// but we're going to let someone else handle it, probably the mesos task error handler
|
||||||
return "", fmt.Errorf("task %s has already been launched, aborting schedule", task.ID)
|
return "", fmt.Errorf("task %s has already been launched, aborting schedule", task.ID)
|
||||||
} else {
|
} else {
|
||||||
return k.doSchedule(task, nil)
|
return k.doSchedule(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -303,8 +307,10 @@ func (k *kubeScheduler) Schedule(pod *api.Pod, unused algorithm.NodeLister) (str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call ScheduleFunc and subtract some resources, returning the name of the machine the task is scheduled on
|
// Call ScheduleFunc and subtract some resources, returning the name of the machine the task is scheduled on
|
||||||
func (k *kubeScheduler) doSchedule(task *podtask.T, err error) (string, error) {
|
func (k *kubeScheduler) doSchedule(task *podtask.T) (string, error) {
|
||||||
var offer offers.Perishable
|
var offer offers.Perishable
|
||||||
|
var err error
|
||||||
|
|
||||||
if task.HasAcceptedOffer() {
|
if task.HasAcceptedOffer() {
|
||||||
// verify that the offer is still on the table
|
// verify that the offer is still on the table
|
||||||
offerId := task.GetOfferId()
|
offerId := task.GetOfferId()
|
||||||
@ -319,7 +325,7 @@ func (k *kubeScheduler) doSchedule(task *podtask.T, err error) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil && offer == nil {
|
if offer == nil {
|
||||||
offer, err = k.api.algorithm().SchedulePod(k.api.offers(), k.api, task)
|
offer, err = k.api.algorithm().SchedulePod(k.api.offers(), k.api, task)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user