Skip to content

Commit

Permalink
add: disable-scheduler-estimator-in-pull-mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
prodanlabs committed Jun 27, 2022
1 parent 403db45 commit 788ffa5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
6 changes: 3 additions & 3 deletions cmd/scheduler/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Options struct {

// EnableSchedulerEstimator represents whether the accurate scheduler estimator should be enabled.
EnableSchedulerEstimator bool
// EnablePullSchedulerEstimatorEvent represents whether the pull mode enabled the accurate scheduler estimator event.
EnablePullSchedulerEstimatorEvent bool
// DisableSchedulerEstimatorInPullMode represents whether to disable the pull mode scheduler estimator.
DisableSchedulerEstimatorInPullMode bool
// SchedulerEstimatorTimeout specifies the timeout period of calling the accurate scheduler estimator service.
SchedulerEstimatorTimeout metav1.Duration
// SchedulerEstimatorPort is the port that the accurate scheduler estimator server serves at.
Expand Down Expand Up @@ -82,7 +82,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.")
fs.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.")
fs.BoolVar(&o.EnableSchedulerEstimator, "enable-scheduler-estimator", false, "Enable calling cluster scheduler estimator for adjusting replicas.")
fs.BoolVar(&o.EnablePullSchedulerEstimatorEvent, "enable-pull-scheduler-estimator-event", true, "Enable scheduler estimator event handler in pull mode.")
fs.BoolVar(&o.DisableSchedulerEstimatorInPullMode, "disable-scheduler-estimator-in-pull-mode", false, "Disable the pull mode scheduler estimator.")
fs.DurationVar(&o.SchedulerEstimatorTimeout.Duration, "scheduler-estimator-timeout", 3*time.Second, "Specifies the timeout period of calling the scheduler estimator service.")
fs.IntVar(&o.SchedulerEstimatorPort, "scheduler-estimator-port", defaultEstimatorPort, "The secure port on which to connect the accurate scheduler estimator.")
fs.BoolVar(&o.EnableEmptyWorkloadPropagation, "enable-empty-workload-propagation", false, "Enable workload with replicas 0 to be propagated to member clusters.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/scheduler/app/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ func run(opts *options.Options, stopChan <-chan struct{}, registryOptions ...Opt
sched, err := scheduler.NewScheduler(dynamicClientSet, karmadaClient, kubeClientSet,
scheduler.WithOutOfTreeRegistry(outOfTreeRegistry),
scheduler.WithEnableSchedulerEstimator(opts.EnableSchedulerEstimator),
scheduler.WithDisableSchedulerEstimatorInPullMode(opts.DisableSchedulerEstimatorInPullMode),
scheduler.WithSchedulerEstimatorPort(opts.SchedulerEstimatorPort),
scheduler.WithSchedulerEstimatorTimeout(opts.SchedulerEstimatorTimeout),
scheduler.WithEnableEmptyWorkloadPropagation(opts.EnableEmptyWorkloadPropagation),
scheduler.WithEnablePullSchedulerEstimatorEvent(opts.EnablePullSchedulerEstimatorEvent),
)
if err != nil {
return fmt.Errorf("couldn't create scheduler: %w", err)
Expand Down
14 changes: 3 additions & 11 deletions pkg/scheduler/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *Scheduler) addCluster(obj interface{}) {
}
klog.V(3).Infof("Add event for cluster %s", cluster.Name)

if s.enableSchedulerEstimatorEvent(cluster.Spec.SyncMode) {
if s.enableSchedulerEstimator {
s.schedulerEstimatorWorker.Add(cluster.Name)
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *Scheduler) updateCluster(_, newObj interface{}) {
}
klog.V(3).Infof("Update event for cluster %s", newCluster.Name)

if s.enableSchedulerEstimatorEvent(newCluster.Spec.SyncMode) {
if s.enableSchedulerEstimator {
s.schedulerEstimatorWorker.Add(newCluster.Name)
}

Expand Down Expand Up @@ -283,15 +283,7 @@ func (s *Scheduler) deleteCluster(obj interface{}) {
s.enqueueAffectedBinding(cluster.Name)
s.enqueueAffectedClusterBinding(cluster.Name)

if s.enableSchedulerEstimatorEvent(cluster.Spec.SyncMode) {
if s.enableSchedulerEstimator {
s.schedulerEstimatorWorker.Add(cluster.Name)
}
}

func (s *Scheduler) enableSchedulerEstimatorEvent(clusterSyncMode clusterv1alpha1.ClusterSyncMode) bool {
if s.enableSchedulerEstimator && clusterSyncMode == clusterv1alpha1.Pull {
return s.enablePullSchedulerEstimatorEvent
}

return s.enableSchedulerEstimator
}
25 changes: 14 additions & 11 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ type Scheduler struct {

eventRecorder record.EventRecorder

enableSchedulerEstimator bool
enablePullSchedulerEstimatorEvent bool
schedulerEstimatorCache *estimatorclient.SchedulerEstimatorCache
schedulerEstimatorPort int
schedulerEstimatorWorker util.AsyncWorker
enableSchedulerEstimator bool
disableSchedulerEstimatorInPullMode bool
schedulerEstimatorCache *estimatorclient.SchedulerEstimatorCache
schedulerEstimatorPort int
schedulerEstimatorWorker util.AsyncWorker

enableEmptyWorkloadPropagation bool
}

type schedulerOptions struct {
// enableSchedulerEstimator represents whether the accurate scheduler estimator should be enabled.
enableSchedulerEstimator bool
// enablePullSchedulerEstimatorEvent represents whether the pull mode enabled the accurate scheduler estimator event.
enablePullSchedulerEstimatorEvent bool
// disableSchedulerEstimatorInPullMode represents whether to disable the pull mode scheduler estimator.
disableSchedulerEstimatorInPullMode bool
// schedulerEstimatorTimeout specifies the timeout period of calling the accurate scheduler estimator service.
schedulerEstimatorTimeout metav1.Duration
// schedulerEstimatorPort is the port that the accurate scheduler estimator server serves at.
Expand All @@ -114,10 +114,10 @@ func WithEnableSchedulerEstimator(enableSchedulerEstimator bool) Option {
}
}

// WithEnablePullSchedulerEstimatorEvent sets the enablePullSchedulerEstimatorEvent for scheduler
func WithEnablePullSchedulerEstimatorEvent(enablePullSchedulerEstimatorEvent bool) Option {
// WithDisableSchedulerEstimatorInPullMode sets the disableSchedulerEstimatorInPullMode for scheduler
func WithDisableSchedulerEstimatorInPullMode(disableSchedulerEstimatorInPullMode bool) Option {
return func(o *schedulerOptions) {
o.enablePullSchedulerEstimatorEvent = enablePullSchedulerEstimatorEvent
o.disableSchedulerEstimatorInPullMode = disableSchedulerEstimatorInPullMode
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func NewScheduler(dynamicClient dynamic.Interface, karmadaClient karmadaclientse

if options.enableSchedulerEstimator {
sched.enableSchedulerEstimator = options.enableSchedulerEstimator
sched.enablePullSchedulerEstimatorEvent = options.enablePullSchedulerEstimatorEvent
sched.disableSchedulerEstimatorInPullMode = options.disableSchedulerEstimatorInPullMode
sched.schedulerEstimatorPort = options.schedulerEstimatorPort
sched.schedulerEstimatorCache = estimatorclient.NewSchedulerEstimatorCache()
schedulerEstimatorWorkerOptions := util.Options{
Expand Down Expand Up @@ -604,6 +604,9 @@ func (s *Scheduler) establishEstimatorConnections() {
return
}
for i := range clusterList.Items {
if clusterList.Items[i].Spec.SyncMode == clusterv1alpha1.Pull && s.disableSchedulerEstimatorInPullMode {
continue
}
if err = estimatorclient.EstablishConnection(clusterList.Items[i].Name, s.schedulerEstimatorCache, s.schedulerEstimatorPort); err != nil {
klog.Error(err)
}
Expand Down

0 comments on commit 788ffa5

Please sign in to comment.