Skip to content

Commit

Permalink
feat: improve configuration of concurrent yurtstaticset workers (#1915)…
Browse files Browse the repository at this point in the history
… (#1922)

Signed-off-by: Chenzhao Huang <[email protected]>
  • Loading branch information
huangchenzhao authored Jan 16, 2024
1 parent a6b0442 commit 380ea01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
5 changes: 4 additions & 1 deletion cmd/yurt-manager/app/options/yurtstaticsetcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type YurtStaticSetControllerOptions struct {
func NewYurtStaticSetControllerOptions() *YurtStaticSetControllerOptions {
return &YurtStaticSetControllerOptions{
&config.YurtStaticSetControllerConfiguration{
UpgradeWorkerImage: DefaultUpgradeWorkerImage,
UpgradeWorkerImage: DefaultUpgradeWorkerImage,
ConcurrentYurtStaticSetWorkers: 3,
},
}
}
Expand All @@ -43,6 +44,7 @@ func (o *YurtStaticSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
}

fs.StringVar(&o.UpgradeWorkerImage, "node-servant-image", o.UpgradeWorkerImage, "Specify node servant pod image used for YurtStaticSet upgrade.")
fs.Int32Var(&o.ConcurrentYurtStaticSetWorkers, "concurrent-yurtstaticset-workers", o.ConcurrentYurtStaticSetWorkers, "The number of yurtstaticset objects that are allowed to reconcile concurrently. Larger number = more responsive yurtstaticsets, but more CPU (and network) load")
}

// ApplyTo fills up YurtStaticSet config with options.
Expand All @@ -51,6 +53,7 @@ func (o *YurtStaticSetControllerOptions) ApplyTo(cfg *config.YurtStaticSetContro
return nil
}
cfg.UpgradeWorkerImage = o.UpgradeWorkerImage
cfg.ConcurrentYurtStaticSetWorkers = o.ConcurrentYurtStaticSetWorkers
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/yurtmanager/controller/yurtstaticset/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package config
// YurtStaticSetControllerConfiguration contains elements describing YurtStaticSetController.
type YurtStaticSetControllerConfiguration struct {
// UpgradeWorkerImage specify the image used to execute the upgrade task
UpgradeWorkerImage string
UpgradeWorkerImage string
ConcurrentYurtStaticSetWorkers int32
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package yurtstaticset

import (
"context"
"flag"
"fmt"
"strings"

Expand Down Expand Up @@ -50,14 +49,9 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtstaticset/util"
)

func init() {
flag.IntVar(&concurrentReconciles, "yurtstaticset-workers", concurrentReconciles, "Max concurrent workers for YurtStaticSet controller.")
}

var (
concurrentReconciles = 3
controllerResource = appsv1alpha1.SchemeGroupVersion.WithResource("yurtstaticsets")
True = true
controllerResource = appsv1alpha1.SchemeGroupVersion.WithResource("yurtstaticsets")
True = true
)

const (
Expand Down Expand Up @@ -133,7 +127,7 @@ func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager)
}

klog.Infof("yurtstaticset-controller add controller %s", controllerResource.String())
return add(mgr, newReconciler(c, mgr))
return add(mgr, c, newReconciler(c, mgr))
}

var _ reconcile.Reconciler = &ReconcileYurtStaticSet{}
Expand All @@ -157,9 +151,9 @@ func newReconciler(c *appconfig.CompletedConfig, mgr manager.Manager) reconcile.
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
func add(mgr manager.Manager, cfg *appconfig.CompletedConfig, r reconcile.Reconciler) error {
// Create a new controller
c, err := controller.New(names.YurtStaticSetController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: concurrentReconciles})
c, err := controller.New(names.YurtStaticSetController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.YurtStaticSetController.ConcurrentYurtStaticSetWorkers)})
if err != nil {
return err
}
Expand Down

0 comments on commit 380ea01

Please sign in to comment.