Skip to content

Commit 609bf00

Browse files
authored
Merge pull request kubernetes#130189 from ania-borowiec/129967_get_rid_of_caching_cluster_events_in_binding
Call queue.Done() before PreBind phase, removing the pod in binding from inFlightPods to save memory
2 parents 507eee8 + 17acc4a commit 609bf00

File tree

3 files changed

+514
-99
lines changed

3 files changed

+514
-99
lines changed

pkg/scheduler/backend/queue/scheduling_queue.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ type SchedulingQueue interface {
134134
PodsInActiveQ() []*v1.Pod
135135
// PodsInBackoffQ returns all the Pods in the backoffQ.
136136
PodsInBackoffQ() []*v1.Pod
137+
UnschedulablePods() []*v1.Pod
137138
}
138139

139140
// NewSchedulingQueue initializes a priority queue as a new scheduling queue.
@@ -1205,6 +1206,15 @@ func (p *PriorityQueue) PodsInBackoffQ() []*v1.Pod {
12051206
return p.backoffQ.list()
12061207
}
12071208

1209+
// UnschedulablePods returns all the pods in unschedulable state.
1210+
func (p *PriorityQueue) UnschedulablePods() []*v1.Pod {
1211+
var result []*v1.Pod
1212+
for _, pInfo := range p.unschedulablePods.podInfoMap {
1213+
result = append(result, pInfo.Pod)
1214+
}
1215+
return result
1216+
}
1217+
12081218
var pendingPodsSummary = "activeQ:%v; backoffQ:%v; unschedulablePods:%v"
12091219

12101220
// GetPod searches for a pod in the activeQ, backoffQ, and unschedulablePods.
@@ -1241,9 +1251,9 @@ func (p *PriorityQueue) GetPod(name, namespace string) (pInfo *framework.QueuedP
12411251
func (p *PriorityQueue) PendingPods() ([]*v1.Pod, string) {
12421252
p.lock.RLock()
12431253
defer p.lock.RUnlock()
1244-
result := p.activeQ.list()
1254+
result := p.PodsInActiveQ()
12451255
activeQLen := len(result)
1246-
backoffQPods := p.backoffQ.list()
1256+
backoffQPods := p.PodsInBackoffQ()
12471257
backoffQLen := len(backoffQPods)
12481258
result = append(result, backoffQPods...)
12491259
for _, pInfo := range p.unschedulablePods.podInfoMap {

pkg/scheduler/schedule_one.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,19 @@ func (sched *Scheduler) bindingCycle(
292292
return status
293293
}
294294

295-
// Run "prebind" plugins.
296-
if status := fwk.RunPreBindPlugins(ctx, state, assumedPod, scheduleResult.SuggestedHost); !status.IsSuccess() {
297-
if status.IsRejected() {
298-
fitErr := &framework.FitError{
299-
NumAllNodes: 1,
300-
Pod: assumedPodInfo.Pod,
301-
Diagnosis: framework.Diagnosis{
302-
NodeToStatus: framework.NewDefaultNodeToStatus(),
303-
UnschedulablePlugins: sets.New(status.Plugin()),
304-
},
305-
}
306-
fitErr.Diagnosis.NodeToStatus.Set(scheduleResult.SuggestedHost, status)
307-
return framework.NewStatus(status.Code()).WithError(fitErr)
308-
}
309-
return status
310-
}
311-
312295
// Any failures after this point cannot lead to the Pod being considered unschedulable.
313-
// We define the Pod as "unschedulable" only when Pods are rejected at specific extension points, and PreBind is the last one in the scheduling/binding cycle.
296+
// We define the Pod as "unschedulable" only when Pods are rejected at specific extension points, and Permit is the last one in the scheduling/binding cycle.
297+
// If a Pod fails on PreBind or Bind, it should be moved to BackoffQ for retry.
314298
//
315299
// We can call Done() here because
316-
// we can free the cluster events stored in the scheduling queue sonner, which is worth for busy clusters memory consumption wise.
300+
// we can free the cluster events stored in the scheduling queue sooner, which is worth for busy clusters memory consumption wise.
317301
sched.SchedulingQueue.Done(assumedPod.UID)
318302

303+
// Run "prebind" plugins.
304+
if status := fwk.RunPreBindPlugins(ctx, state, assumedPod, scheduleResult.SuggestedHost); !status.IsSuccess() {
305+
return status
306+
}
307+
319308
// Run "bind" plugins.
320309
if status := sched.bind(ctx, fwk, assumedPod, scheduleResult.SuggestedHost, state); !status.IsSuccess() {
321310
return status

0 commit comments

Comments
 (0)