schedulerOptions add support for RateLimiterOptions
Signed-off-by: huangyanfeng <huangyanfeng1992@gmail.com>
This commit is contained in:
parent
48e936957e
commit
fec30e0380
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler"
|
"github.com/karmada-io/karmada/pkg/scheduler"
|
||||||
frameworkplugins "github.com/karmada-io/karmada/pkg/scheduler/framework/plugins"
|
frameworkplugins "github.com/karmada-io/karmada/pkg/scheduler/framework/plugins"
|
||||||
"github.com/karmada-io/karmada/pkg/sharedcli/profileflag"
|
"github.com/karmada-io/karmada/pkg/sharedcli/profileflag"
|
||||||
|
"github.com/karmada-io/karmada/pkg/sharedcli/ratelimiterflag"
|
||||||
"github.com/karmada-io/karmada/pkg/util"
|
"github.com/karmada-io/karmada/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,6 +69,9 @@ type Options struct {
|
||||||
// SchedulerName represents the name of the scheduler.
|
// SchedulerName represents the name of the scheduler.
|
||||||
// default is "default-scheduler".
|
// default is "default-scheduler".
|
||||||
SchedulerName string
|
SchedulerName string
|
||||||
|
|
||||||
|
// RateLimiterOpts contains the options for rate limiter.
|
||||||
|
RateLimiterOpts ratelimiterflag.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOptions builds an default scheduler options.
|
// NewOptions builds an default scheduler options.
|
||||||
|
@ -111,4 +115,5 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||||
fs.StringVar(&o.SchedulerName, "scheduler-name", scheduler.DefaultScheduler, "SchedulerName represents the name of the scheduler. default is 'default-scheduler'.")
|
fs.StringVar(&o.SchedulerName, "scheduler-name", scheduler.DefaultScheduler, "SchedulerName represents the name of the scheduler. default is 'default-scheduler'.")
|
||||||
features.FeatureGate.AddFlag(fs)
|
features.FeatureGate.AddFlag(fs)
|
||||||
o.ProfileOpts.AddFlags(fs)
|
o.ProfileOpts.AddFlags(fs)
|
||||||
|
o.RateLimiterOpts.AddFlags(fs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ func run(opts *options.Options, stopChan <-chan struct{}, registryOptions ...Opt
|
||||||
scheduler.WithEnableEmptyWorkloadPropagation(opts.EnableEmptyWorkloadPropagation),
|
scheduler.WithEnableEmptyWorkloadPropagation(opts.EnableEmptyWorkloadPropagation),
|
||||||
scheduler.WithEnableSchedulerPlugin(opts.Plugins),
|
scheduler.WithEnableSchedulerPlugin(opts.Plugins),
|
||||||
scheduler.WithSchedulerName(opts.SchedulerName),
|
scheduler.WithSchedulerName(opts.SchedulerName),
|
||||||
|
scheduler.WithRateLimiterOptions(opts.RateLimiterOpts),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("couldn't create scheduler: %w", err)
|
return fmt.Errorf("couldn't create scheduler: %w", err)
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
frameworkplugins "github.com/karmada-io/karmada/pkg/scheduler/framework/plugins"
|
frameworkplugins "github.com/karmada-io/karmada/pkg/scheduler/framework/plugins"
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/framework/runtime"
|
"github.com/karmada-io/karmada/pkg/scheduler/framework/runtime"
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/metrics"
|
"github.com/karmada-io/karmada/pkg/scheduler/metrics"
|
||||||
|
"github.com/karmada-io/karmada/pkg/sharedcli/ratelimiterflag"
|
||||||
"github.com/karmada-io/karmada/pkg/util"
|
"github.com/karmada-io/karmada/pkg/util"
|
||||||
"github.com/karmada-io/karmada/pkg/util/helper"
|
"github.com/karmada-io/karmada/pkg/util/helper"
|
||||||
utilmetrics "github.com/karmada-io/karmada/pkg/util/metrics"
|
utilmetrics "github.com/karmada-io/karmada/pkg/util/metrics"
|
||||||
|
@ -114,6 +115,8 @@ type schedulerOptions struct {
|
||||||
outOfTreeRegistry runtime.Registry
|
outOfTreeRegistry runtime.Registry
|
||||||
// plugins is the list of plugins to enable or disable
|
// plugins is the list of plugins to enable or disable
|
||||||
plugins []string
|
plugins []string
|
||||||
|
// contains the options for rate limiter.
|
||||||
|
RateLimiterOptions ratelimiterflag.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option configures a Scheduler
|
// Option configures a Scheduler
|
||||||
|
@ -183,20 +186,26 @@ func WithOutOfTreeRegistry(registry runtime.Registry) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRateLimiterOptions sets the rateLimiterOptions for scheduler
|
||||||
|
func WithRateLimiterOptions(rateLimiterOptions ratelimiterflag.Options) Option {
|
||||||
|
return func(o *schedulerOptions) {
|
||||||
|
o.RateLimiterOptions = rateLimiterOptions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewScheduler instantiates a scheduler
|
// NewScheduler instantiates a scheduler
|
||||||
func NewScheduler(dynamicClient dynamic.Interface, karmadaClient karmadaclientset.Interface, kubeClient kubernetes.Interface, opts ...Option) (*Scheduler, error) {
|
func NewScheduler(dynamicClient dynamic.Interface, karmadaClient karmadaclientset.Interface, kubeClient kubernetes.Interface, opts ...Option) (*Scheduler, error) {
|
||||||
factory := informerfactory.NewSharedInformerFactory(karmadaClient, 0)
|
factory := informerfactory.NewSharedInformerFactory(karmadaClient, 0)
|
||||||
bindingLister := factory.Work().V1alpha2().ResourceBindings().Lister()
|
bindingLister := factory.Work().V1alpha2().ResourceBindings().Lister()
|
||||||
clusterBindingLister := factory.Work().V1alpha2().ClusterResourceBindings().Lister()
|
clusterBindingLister := factory.Work().V1alpha2().ClusterResourceBindings().Lister()
|
||||||
clusterLister := factory.Cluster().V1alpha1().Clusters().Lister()
|
clusterLister := factory.Cluster().V1alpha1().Clusters().Lister()
|
||||||
queue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "scheduler-queue")
|
|
||||||
schedulerCache := schedulercache.NewCache(clusterLister)
|
schedulerCache := schedulercache.NewCache(clusterLister)
|
||||||
|
|
||||||
options := schedulerOptions{}
|
options := schedulerOptions{}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&options)
|
opt(&options)
|
||||||
}
|
}
|
||||||
|
queue := workqueue.NewRateLimitingQueueWithConfig(ratelimiterflag.DefaultControllerRateLimiter(options.RateLimiterOptions), workqueue.RateLimitingQueueConfig{Name: "scheduler-queue"})
|
||||||
registry := frameworkplugins.NewInTreeRegistry()
|
registry := frameworkplugins.NewInTreeRegistry()
|
||||||
if err := registry.Merge(options.outOfTreeRegistry); err != nil {
|
if err := registry.Merge(options.outOfTreeRegistry); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue