Clean shutdown of kcm, ccm and scheduler

This commit is contained in:
Wojciech Tyczyński
2022-05-25 10:00:06 +02:00
parent 55130ae2ab
commit fe3616cafb
10 changed files with 72 additions and 38 deletions

View File

@@ -335,7 +335,16 @@ func New(client clientset.Interface,
// Run begins watching and scheduling. It starts scheduling and blocked until the context is done.
func (sched *Scheduler) Run(ctx context.Context) {
sched.SchedulingQueue.Run()
wait.UntilWithContext(ctx, sched.scheduleOne, 0)
// We need to start scheduleOne loop in a dedicated goroutine,
// because scheduleOne function hangs on getting the next item
// from the SchedulingQueue.
// If there are no new pods to schedule, it will be hanging there
// and if done in this goroutine it will be blocking closing
// SchedulingQueue, in effect causing a deadlock on shutdown.
go wait.UntilWithContext(ctx, sched.scheduleOne, 0)
<-ctx.Done()
sched.SchedulingQueue.Close()
}