add ratelimiter flags for karmada-agent

Signed-off-by: dddddai <dddwq@foxmail.com>
This commit is contained in:
dddddai 2022-03-19 15:02:00 +08:00
parent d0553bf3da
commit e52e02c23a
4 changed files with 11 additions and 3 deletions

View File

@ -187,6 +187,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
ClusterAPIQPS: opts.ClusterAPIQPS,
ClusterAPIBurst: opts.ClusterAPIBurst,
ConcurrentWorkSyncs: opts.ConcurrentWorkSyncs,
RateLimiterOptions: opts.RateLimiterOpts,
},
StopChan: stopChan,
}
@ -219,6 +220,7 @@ func startClusterStatusController(ctx controllerscontext.Context) (bool, error)
ClusterLeaseDuration: ctx.Opts.ClusterLeaseDuration,
ClusterLeaseRenewIntervalFraction: ctx.Opts.ClusterLeaseRenewIntervalFraction,
ClusterCacheSyncTimeout: ctx.Opts.ClusterCacheSyncTimeout,
RateLimiterOptions: ctx.Opts.RateLimiterOptions,
}
if err := clusterStatusController.SetupWithManager(ctx.Mgr); err != nil {
return false, err
@ -235,6 +237,7 @@ func startExecutionController(ctx controllerscontext.Context) (bool, error) {
PredicateFunc: helper.NewExecutionPredicateOnAgent(),
InformerManager: informermanager.GetInstance(),
ClusterClientSetFunc: util.NewClusterDynamicClientSetForAgent,
RatelimiterOptions: ctx.Opts.RateLimiterOptions,
}
if err := executionController.SetupWithManager(ctx.Mgr); err != nil {
return false, err
@ -254,6 +257,7 @@ func startWorkStatusController(ctx controllerscontext.Context) (bool, error) {
ClusterClientSetFunc: util.NewClusterDynamicClientSetForAgent,
ClusterCacheSyncTimeout: ctx.Opts.ClusterCacheSyncTimeout,
ConcurrentWorkStatusSyncs: ctx.Opts.ConcurrentWorkSyncs,
RateLimiterOptions: ctx.Opts.RateLimiterOptions,
}
workStatusController.RunWorkQueue()
if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil {

View File

@ -10,6 +10,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
componentbaseconfig "k8s.io/component-base/config"
"github.com/karmada-io/karmada/pkg/sharedcli/ratelimiterflag"
"github.com/karmada-io/karmada/pkg/util"
)
@ -61,6 +62,8 @@ type Options struct {
// ConcurrentWorkSyncs is the number of work objects that are
// allowed to sync concurrently.
ConcurrentWorkSyncs int
RateLimiterOpts ratelimiterflag.Options
}
// NewOptions builds an default scheduler options.
@ -105,4 +108,5 @@ func (o *Options) AddFlags(fs *pflag.FlagSet, allControllers []string) {
fs.DurationVar(&o.ResyncPeriod.Duration, "resync-period", 0, "Base frequency the informers are resynced.")
fs.IntVar(&o.ConcurrentClusterSyncs, "concurrent-cluster-syncs", 5, "The number of Clusters that are allowed to sync concurrently.")
fs.IntVar(&o.ConcurrentWorkSyncs, "concurrent-work-syncs", 5, "The number of Works that are allowed to sync concurrently.")
o.RateLimiterOpts.AddFlags(fs)
}

View File

@ -275,7 +275,7 @@ func startExecutionController(ctx controllerscontext.Context) (enabled bool, err
PredicateFunc: helper.NewExecutionPredicate(ctx.Mgr),
InformerManager: informermanager.GetInstance(),
ClusterClientSetFunc: util.NewClusterDynamicClientSet,
RatelimiterOption: ctx.Opts.RateLimiterOptions,
RatelimiterOptions: ctx.Opts.RateLimiterOptions,
}
if err := executionController.SetupWithManager(ctx.Mgr); err != nil {
return false, err

View File

@ -43,7 +43,7 @@ type Controller struct {
PredicateFunc predicate.Predicate
InformerManager informermanager.MultiClusterInformerManager
ClusterClientSetFunc func(clusterName string, client client.Client) (*util.DynamicClusterClient, error)
RatelimiterOption ratelimiterflag.Options
RatelimiterOptions ratelimiterflag.Options
}
// Reconcile performs a full reconciliation for the object referred to by the Request.
@ -104,7 +104,7 @@ func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
WithEventFilter(predicate.GenerationChangedPredicate{}).
WithEventFilter(c.PredicateFunc).
WithOptions(controller.Options{
RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RatelimiterOption),
RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RatelimiterOptions),
}).
Complete(c)
}