mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
feat: use scheduler.New instead in createSchedulerConfigurator
This commit is contained in:
@@ -30,8 +30,9 @@ import (
|
||||
|
||||
// import DefaultProvider
|
||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider/defaults"
|
||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
)
|
||||
|
||||
@@ -59,7 +60,7 @@ func StartApiserver() (string, ShutdownFunc) {
|
||||
// StartScheduler configures and starts a scheduler given a handle to the clientSet interface
|
||||
// and event broadcaster. It returns a handle to the configurator args for the running scheduler
|
||||
// and the shutdown function to stop it.
|
||||
func StartScheduler(clientSet clientset.Interface) (*factory.ConfigFactoryArgs, ShutdownFunc) {
|
||||
func StartScheduler(clientSet clientset.Interface) (*factory.Config, ShutdownFunc) {
|
||||
informerFactory := informers.NewSharedInformerFactory(clientSet, 0)
|
||||
stopCh := make(chan struct{})
|
||||
evtBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{
|
||||
@@ -67,16 +68,15 @@ func StartScheduler(clientSet clientset.Interface) (*factory.ConfigFactoryArgs,
|
||||
|
||||
evtBroadcaster.StartRecordingToSink(stopCh)
|
||||
|
||||
configuratorArgs := createSchedulerConfiguratorArgs(clientSet, informerFactory, stopCh)
|
||||
configurator := factory.NewConfigFactory(configuratorArgs)
|
||||
recorder := evtBroadcaster.NewRecorder(
|
||||
legacyscheme.Scheme,
|
||||
v1.DefaultSchedulerName,
|
||||
)
|
||||
|
||||
config, err := configurator.CreateFromConfig(schedulerapi.Policy{})
|
||||
sched, err := createScheduler(clientSet, informerFactory, recorder, stopCh)
|
||||
if err != nil {
|
||||
klog.Fatalf("Error creating scheduler: %v", err)
|
||||
}
|
||||
config.Recorder = evtBroadcaster.NewRecorder(legacyscheme.Scheme, "scheduler")
|
||||
|
||||
sched := scheduler.NewFromConfig(config)
|
||||
scheduler.AddAllEventHandlers(sched,
|
||||
v1.DefaultSchedulerName,
|
||||
informerFactory.Core().V1().Nodes(),
|
||||
@@ -96,32 +96,38 @@ func StartScheduler(clientSet clientset.Interface) (*factory.ConfigFactoryArgs,
|
||||
close(stopCh)
|
||||
klog.Infof("destroyed scheduler")
|
||||
}
|
||||
return configuratorArgs, shutdownFunc
|
||||
return sched.Config(), shutdownFunc
|
||||
}
|
||||
|
||||
// createSchedulerConfigurator create a configurator for scheduler with given informer factory.
|
||||
func createSchedulerConfiguratorArgs(
|
||||
// createScheduler create a scheduler with given informer factory and default name.
|
||||
func createScheduler(
|
||||
clientSet clientset.Interface,
|
||||
informerFactory informers.SharedInformerFactory,
|
||||
recorder events.EventRecorder,
|
||||
stopCh <-chan struct{},
|
||||
) *factory.ConfigFactoryArgs {
|
||||
) (*scheduler.Scheduler, error) {
|
||||
defaultProviderName := schedulerconfig.SchedulerDefaultProviderName
|
||||
|
||||
return &factory.ConfigFactoryArgs{
|
||||
Client: clientSet,
|
||||
NodeInformer: informerFactory.Core().V1().Nodes(),
|
||||
PodInformer: informerFactory.Core().V1().Pods(),
|
||||
PvInformer: informerFactory.Core().V1().PersistentVolumes(),
|
||||
PvcInformer: informerFactory.Core().V1().PersistentVolumeClaims(),
|
||||
ReplicationControllerInformer: informerFactory.Core().V1().ReplicationControllers(),
|
||||
ReplicaSetInformer: informerFactory.Apps().V1().ReplicaSets(),
|
||||
StatefulSetInformer: informerFactory.Apps().V1().StatefulSets(),
|
||||
ServiceInformer: informerFactory.Core().V1().Services(),
|
||||
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
|
||||
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
|
||||
CSINodeInformer: informerFactory.Storage().V1beta1().CSINodes(),
|
||||
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
|
||||
DisablePreemption: false,
|
||||
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
||||
StopCh: stopCh,
|
||||
}
|
||||
return scheduler.New(
|
||||
clientSet,
|
||||
informerFactory.Core().V1().Nodes(),
|
||||
informerFactory.Core().V1().Pods(),
|
||||
informerFactory.Core().V1().PersistentVolumes(),
|
||||
informerFactory.Core().V1().PersistentVolumeClaims(),
|
||||
informerFactory.Core().V1().ReplicationControllers(),
|
||||
informerFactory.Apps().V1().ReplicaSets(),
|
||||
informerFactory.Apps().V1().StatefulSets(),
|
||||
informerFactory.Core().V1().Services(),
|
||||
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
|
||||
informerFactory.Storage().V1().StorageClasses(),
|
||||
informerFactory.Storage().V1beta1().CSINodes(),
|
||||
recorder,
|
||||
schedulerconfig.SchedulerAlgorithmSource{
|
||||
Provider: &defaultProviderName,
|
||||
},
|
||||
stopCh,
|
||||
schedulerframework.NewRegistry(),
|
||||
nil,
|
||||
[]schedulerconfig.PluginConfig{},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user