From 76a42fb29ba1bbb17616e46bededa050546f1fcf Mon Sep 17 00:00:00 2001 From: draveness Date: Thu, 24 Oct 2019 10:16:59 +0800 Subject: [PATCH] feat: remove WaitForCacheSync from scheduler factory --- pkg/scheduler/factory.go | 18 ++++-------------- pkg/scheduler/scheduler.go | 11 +++++------ pkg/scheduler/scheduler_test.go | 2 +- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 6e8a8a0b8cf..c7ec60d747f 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -86,10 +86,6 @@ type Config struct { // stale while they sit in a channel. NextPod func() *framework.PodInfo - // WaitForCacheSync waits for scheduler cache to populate. - // It returns true if it was successful, false if the controller should shutdown. - WaitForCacheSync func() bool - // Error is called if there is an error. It is passed the pod in // question, and the error Error func(*framework.PodInfo, error) @@ -147,8 +143,6 @@ type Configurator struct { // Close this to stop all reflectors StopEverything <-chan struct{} - scheduledPodsHasSynced cache.InformerSynced - schedulerCache internalcache.Cache // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule @@ -261,7 +255,6 @@ func NewConfigFactory(args *ConfigFactoryArgs) *Configurator { pluginConfig: args.PluginConfig, pluginConfigProducerRegistry: args.PluginConfigProducerRegistry, } - c.scheduledPodsHasSynced = args.PodInformer.Informer().HasSynced return c } @@ -454,13 +447,10 @@ func (c *Configurator) CreateFromKeys(predicateKeys, priorityKeys sets.String, e ) return &Config{ - SchedulerCache: c.schedulerCache, - Algorithm: algo, - GetBinder: getBinderFunc(c.client, extenders), - Framework: framework, - WaitForCacheSync: func() bool { - return cache.WaitForCacheSync(c.StopEverything, c.scheduledPodsHasSynced) - }, + SchedulerCache: c.schedulerCache, + Algorithm: algo, + GetBinder: getBinderFunc(c.client, extenders), + Framework: framework, NextPod: internalqueue.MakeNextPodFunc(podQueue), Error: MakeDefaultErrorFunc(c.client, podQueue, c.schedulerCache), StopEverything: c.StopEverything, diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 5b5574466ee..bcfc8226816 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/informers" coreinformers "k8s.io/client-go/informers/core/v1" clientset "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/events" podutil "k8s.io/kubernetes/pkg/api/v1/pod" schedulerapi "k8s.io/kubernetes/pkg/scheduler/api" @@ -95,10 +96,6 @@ type Scheduler struct { // stale while they sit in a channel. NextPod func() *framework.PodInfo - // WaitForCacheSync waits for scheduler cache to populate. - // It returns true if it was successful, false if the controller should shutdown. - WaitForCacheSync func() bool - // Error is called if there is an error. It is passed the pod in // question, and the error Error func(*framework.PodInfo, error) @@ -117,6 +114,8 @@ type Scheduler struct { // SchedulingQueue holds pods to be scheduled SchedulingQueue internalqueue.SchedulingQueue + + scheduledPodsHasSynced func() bool } // Cache returns the cache in scheduler for test to check the data in scheduler. @@ -348,6 +347,7 @@ func New(client clientset.Interface, sched := NewFromConfig(config) sched.podConditionUpdater = &podConditionUpdaterImpl{client} sched.podPreemptor = &podPreemptorImpl{client} + sched.scheduledPodsHasSynced = podInformer.Informer().HasSynced AddAllEventHandlers(sched, options.schedulerName, informerFactory, podInformer) return sched, nil @@ -398,7 +398,6 @@ func NewFromConfig(config *Config) *Scheduler { GetBinder: config.GetBinder, Framework: config.Framework, NextPod: config.NextPod, - WaitForCacheSync: config.WaitForCacheSync, Error: config.Error, Recorder: config.Recorder, StopEverything: config.StopEverything, @@ -410,7 +409,7 @@ func NewFromConfig(config *Config) *Scheduler { // Run begins watching and scheduling. It waits for cache to be synced, then starts scheduling and blocked until the context is done. func (sched *Scheduler) Run(ctx context.Context) { - if !sched.WaitForCacheSync() { + if !cache.WaitForCacheSync(ctx.Done(), sched.scheduledPodsHasSynced) { return } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 8d849e7ec56..9a44dd28787 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -717,7 +717,7 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc return nil }} }, - WaitForCacheSync: func() bool { + scheduledPodsHasSynced: func() bool { return true }, NextPod: func() *framework.PodInfo {