Skip scheduling the pod if it has been assumed and the pod updates could be skipped.

This commit is contained in:
Jun Gong 2019-12-13 09:40:50 +08:00
parent cfdfd043a0
commit 706e90a033
2 changed files with 26 additions and 3 deletions

View File

@ -599,9 +599,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
return
}
pod := podInfo.Pod
if pod.DeletionTimestamp != nil {
sched.Recorder.Eventf(pod, nil, v1.EventTypeWarning, "FailedScheduling", "Scheduling", "skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name)
klog.V(3).Infof("Skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name)
if sched.skipPodSchedule(pod) {
return
}
@ -764,6 +762,25 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
}()
}
// skipPodSchedule returns true if we could skip scheduling the pod for specified cases.
func (sched *Scheduler) skipPodSchedule(pod *v1.Pod) bool {
// Case 1: pod is being deleted.
if pod.DeletionTimestamp != nil {
sched.Recorder.Eventf(pod, nil, v1.EventTypeWarning, "FailedScheduling", "Scheduling", "skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name)
klog.V(3).Infof("Skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name)
return true
}
// Case 2: pod has been assumed and pod updates could be skipped.
// An assumed pod can be added again to the scheduling queue if it got an update event
// during its previous scheduling cycle but before getting assumed.
if sched.skipPodUpdate(pod) {
return true
}
return false
}
type podConditionUpdaterImpl struct {
Client clientset.Interface
}

View File

@ -309,6 +309,12 @@ func TestScheduler(t *testing.T) {
AssumeFunc: func(pod *v1.Pod) {
gotAssumedPod = pod
},
IsAssumedPodFunc: func(pod *v1.Pod) bool {
if pod == nil || gotAssumedPod == nil {
return false
}
return pod.UID == gotAssumedPod.UID
},
}
s := &Scheduler{