mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
sched: start dynamicInformerFactory along with regular informerFactory (#105016)
* sched: start dynamicInformerFactory along with regular informerFactory * fixup: start all informers and then wait for their syncs
This commit is contained in:
@@ -18,6 +18,7 @@ package config
|
||||
|
||||
import (
|
||||
apiserver "k8s.io/apiserver/pkg/server"
|
||||
"k8s.io/client-go/dynamic/dynamicinformer"
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
@@ -40,9 +41,10 @@ type Config struct {
|
||||
Authorization apiserver.AuthorizationInfo
|
||||
SecureServing *apiserver.SecureServingInfo
|
||||
|
||||
Client clientset.Interface
|
||||
KubeConfig *restclient.Config
|
||||
InformerFactory informers.SharedInformerFactory
|
||||
Client clientset.Interface
|
||||
KubeConfig *restclient.Config
|
||||
InformerFactory informers.SharedInformerFactory
|
||||
DynInformerFactory dynamicinformer.DynamicSharedInformerFactory
|
||||
|
||||
//lint:ignore SA1019 this deprecated field still needs to be used for now. It will be removed once the migration is done.
|
||||
EventBroadcaster events.EventBroadcasterAdapter
|
||||
|
@@ -27,6 +27,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/dynamic/dynamicinformer"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
@@ -284,6 +286,8 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) {
|
||||
c.Client = client
|
||||
c.KubeConfig = kubeConfig
|
||||
c.InformerFactory = scheduler.NewInformerFactory(client, 0)
|
||||
dynClient := dynamic.NewForConfigOrDie(kubeConfig)
|
||||
c.DynInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, corev1.NamespaceAll, nil)
|
||||
c.LeaderElection = leaderElectionConfig
|
||||
|
||||
return c, nil
|
||||
|
@@ -180,9 +180,17 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
|
||||
// Start all informers.
|
||||
cc.InformerFactory.Start(ctx.Done())
|
||||
// DynInformerFactory can be nil in tests.
|
||||
if cc.DynInformerFactory != nil {
|
||||
cc.DynInformerFactory.Start(ctx.Done())
|
||||
}
|
||||
|
||||
// Wait for all caches to sync before scheduling.
|
||||
cc.InformerFactory.WaitForCacheSync(ctx.Done())
|
||||
// DynInformerFactory can be nil in tests.
|
||||
if cc.DynInformerFactory != nil {
|
||||
cc.DynInformerFactory.WaitForCacheSync(ctx.Done())
|
||||
}
|
||||
|
||||
// If leader election is enabled, runCommand via LeaderElector until done and exit.
|
||||
if cc.LeaderElection != nil {
|
||||
@@ -303,6 +311,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
|
||||
// Create the scheduler.
|
||||
sched, err := scheduler.New(cc.Client,
|
||||
cc.InformerFactory,
|
||||
cc.DynInformerFactory,
|
||||
recorderFactory,
|
||||
ctx.Done(),
|
||||
scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion),
|
||||
|
Reference in New Issue
Block a user