Skip to content

Commit 3cf8009

Browse files
authored
Merge pull request kubernetes#93044 from Huang-Wei/rm-sched-podInformer
Initialize scheduler's podInformer in sharedInformerFactory
2 parents 5e95af8 + d8def59 commit 3cf8009

File tree

23 files changed

+41
-103
lines changed

23 files changed

+41
-103
lines changed

cmd/kube-scheduler/app/config/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ go_library(
99
"//pkg/scheduler/apis/config:go_default_library",
1010
"//staging/src/k8s.io/apiserver/pkg/server:go_default_library",
1111
"//staging/src/k8s.io/client-go/informers:go_default_library",
12-
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
1312
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
1413
"//staging/src/k8s.io/client-go/rest:go_default_library",
1514
"//staging/src/k8s.io/client-go/tools/events:go_default_library",

cmd/kube-scheduler/app/config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package config
1919
import (
2020
apiserver "k8s.io/apiserver/pkg/server"
2121
"k8s.io/client-go/informers"
22-
coreinformers "k8s.io/client-go/informers/core/v1"
2322
clientset "k8s.io/client-go/kubernetes"
2423
restclient "k8s.io/client-go/rest"
2524
"k8s.io/client-go/tools/events"
@@ -43,7 +42,6 @@ type Config struct {
4342

4443
Client clientset.Interface
4544
InformerFactory informers.SharedInformerFactory
46-
PodInformer coreinformers.PodInformer
4745

4846
//lint:ignore SA1019 this deprecated field still needs to be used for now. It will be removed once the migration is done.
4947
EventBroadcaster events.EventBroadcasterAdapter

cmd/kube-scheduler/app/options/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ go_library(
2626
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
2727
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
2828
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
29-
"//staging/src/k8s.io/client-go/informers:go_default_library",
3029
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
3130
"//staging/src/k8s.io/client-go/rest:go_default_library",
3231
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",

cmd/kube-scheduler/app/options/options.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"k8s.io/apimachinery/pkg/util/uuid"
2929
apiserveroptions "k8s.io/apiserver/pkg/server/options"
3030
utilfeature "k8s.io/apiserver/pkg/util/feature"
31-
"k8s.io/client-go/informers"
3231
clientset "k8s.io/client-go/kubernetes"
3332
restclient "k8s.io/client-go/rest"
3433
"k8s.io/client-go/tools/clientcmd"
@@ -287,8 +286,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) {
287286
}
288287

289288
c.Client = client
290-
c.InformerFactory = informers.NewSharedInformerFactory(client, 0)
291-
c.PodInformer = scheduler.NewPodInformer(client, 0)
289+
c.InformerFactory = scheduler.NewInformerFactory(client, 0)
292290
c.LeaderElection = leaderElectionConfig
293291

294292
return c, nil

cmd/kube-scheduler/app/server.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
185185
}
186186

187187
// Start all informers.
188-
go cc.PodInformer.Informer().Run(ctx.Done())
189188
cc.InformerFactory.Start(ctx.Done())
190189

191190
// Wait for all caches to sync before scheduling.
@@ -316,7 +315,6 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
316315
// Create the scheduler.
317316
sched, err := scheduler.New(cc.Client,
318317
cc.InformerFactory,
319-
cc.PodInformer,
320318
recorderFactory,
321319
ctx.Done(),
322320
scheduler.WithProfiles(cc.ComponentConfig.Profiles...),

pkg/scheduler/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ go_library(
4040
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
4141
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
4242
"//staging/src/k8s.io/client-go/informers:go_default_library",
43-
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
4443
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
4544
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
4645
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",

pkg/scheduler/apis/config/testing/compatibility_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
13381338
sched, err := scheduler.New(
13391339
client,
13401340
informerFactory,
1341-
informerFactory.Core().V1().Pods(),
13421341
recorderFactory,
13431342
make(chan struct{}),
13441343
scheduler.WithAlgorithmSource(algorithmSrc),
@@ -1514,7 +1513,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
15141513
sched, err := scheduler.New(
15151514
client,
15161515
informerFactory,
1517-
informerFactory.Core().V1().Pods(),
15181516
recorderFactory,
15191517
make(chan struct{}),
15201518
opts...,
@@ -1943,7 +1941,6 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
19431941
sched, err := scheduler.New(
19441942
client,
19451943
informerFactory,
1946-
informerFactory.Core().V1().Pods(),
19471944
recorderFactory,
19481945
make(chan struct{}),
19491946
scheduler.WithProfiles(config.KubeSchedulerProfile{

pkg/scheduler/eventhandlers.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2828
utilfeature "k8s.io/apiserver/pkg/util/feature"
2929
"k8s.io/client-go/informers"
30-
coreinformers "k8s.io/client-go/informers/core/v1"
3130
"k8s.io/client-go/tools/cache"
3231
"k8s.io/kubernetes/pkg/features"
3332
"k8s.io/kubernetes/pkg/scheduler/internal/queue"
@@ -362,10 +361,9 @@ func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
362361
func addAllEventHandlers(
363362
sched *Scheduler,
364363
informerFactory informers.SharedInformerFactory,
365-
podInformer coreinformers.PodInformer,
366364
) {
367365
// scheduled pod cache
368-
podInformer.Informer().AddEventHandler(
366+
informerFactory.Core().V1().Pods().Informer().AddEventHandler(
369367
cache.FilteringResourceEventHandler{
370368
FilterFunc: func(obj interface{}) bool {
371369
switch t := obj.(type) {
@@ -390,7 +388,7 @@ func addAllEventHandlers(
390388
},
391389
)
392390
// unscheduled pod queue
393-
podInformer.Informer().AddEventHandler(
391+
informerFactory.Core().V1().Pods().Informer().AddEventHandler(
394392
cache.FilteringResourceEventHandler{
395393
FilterFunc: func(obj interface{}) bool {
396394
switch t := obj.(type) {

pkg/scheduler/factory.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ import (
2727
v1 "k8s.io/api/core/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30-
"k8s.io/apimachinery/pkg/fields"
3130
"k8s.io/apimachinery/pkg/runtime"
3231
"k8s.io/apimachinery/pkg/util/sets"
3332
"k8s.io/client-go/informers"
34-
coreinformers "k8s.io/client-go/informers/core/v1"
3533
clientset "k8s.io/client-go/kubernetes"
3634
corelisters "k8s.io/client-go/listers/core/v1"
37-
"k8s.io/client-go/tools/cache"
3835
"k8s.io/klog/v2"
3936
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
4037
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
@@ -66,8 +63,6 @@ type Configurator struct {
6663

6764
informerFactory informers.SharedInformerFactory
6865

69-
podInformer coreinformers.PodInformer
70-
7166
// Close this to stop all reflectors
7267
StopEverything <-chan struct{}
7368

@@ -178,7 +173,7 @@ func (c *Configurator) create() (*Scheduler, error) {
178173
// Setup cache debugger.
179174
debugger := cachedebugger.New(
180175
c.informerFactory.Core().V1().Nodes().Lister(),
181-
c.podInformer.Lister(),
176+
c.informerFactory.Core().V1().Pods().Lister(),
182177
c.schedulerCache,
183178
podQueue,
184179
)
@@ -412,29 +407,6 @@ func getPredicateConfigs(keys sets.String, lr *frameworkplugins.LegacyRegistry,
412407
return &plugins, pluginConfig, nil
413408
}
414409

415-
type podInformer struct {
416-
informer cache.SharedIndexInformer
417-
}
418-
419-
func (i *podInformer) Informer() cache.SharedIndexInformer {
420-
return i.informer
421-
}
422-
423-
func (i *podInformer) Lister() corelisters.PodLister {
424-
return corelisters.NewPodLister(i.informer.GetIndexer())
425-
}
426-
427-
// NewPodInformer creates a shared index informer that returns only non-terminal pods.
428-
func NewPodInformer(client clientset.Interface, resyncPeriod time.Duration) coreinformers.PodInformer {
429-
selector := fields.ParseSelectorOrDie(
430-
"status.phase!=" + string(v1.PodSucceeded) +
431-
",status.phase!=" + string(v1.PodFailed))
432-
lw := cache.NewListWatchFromClient(client.CoreV1().RESTClient(), string(v1.ResourcePods), metav1.NamespaceAll, selector)
433-
return &podInformer{
434-
informer: cache.NewSharedIndexInformer(lw, &v1.Pod{}, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}),
435-
}
436-
}
437-
438410
// MakeDefaultErrorFunc construct a function to handle pod scheduler error
439411
func MakeDefaultErrorFunc(client clientset.Interface, podLister corelisters.PodLister, podQueue internalqueue.SchedulingQueue, schedulerCache internalcache.Cache) func(*framework.QueuedPodInfo, error) {
440412
return func(podInfo *framework.QueuedPodInfo, err error) {

pkg/scheduler/factory_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ func newConfigFactoryWithFrameworkRegistry(
453453
return &Configurator{
454454
client: client,
455455
informerFactory: informerFactory,
456-
podInformer: informerFactory.Core().V1().Pods(),
457456
disablePreemption: disablePodPreemption,
458457
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
459458
podInitialBackoffSeconds: podInitialBackoffDurationSeconds,

0 commit comments

Comments
 (0)