diff --git a/cmd/yurt-manager/app/options/options.go b/cmd/yurt-manager/app/options/options.go index 4471eeddbd1..8fd228efa25 100644 --- a/cmd/yurt-manager/app/options/options.go +++ b/cmd/yurt-manager/app/options/options.go @@ -26,6 +26,7 @@ import ( // YurtManagerOptions is the main context object for the yurt-manager. type YurtManagerOptions struct { Generic *GenericOptions + PodBindingController *PodBindingControllerOptions DaemonPodUpdaterController *DaemonPodUpdaterControllerOptions CsrApproverController *CsrApproverControllerOptions NodePoolController *NodePoolControllerOptions @@ -43,6 +44,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) { s := YurtManagerOptions{ Generic: NewGenericOptions(), + PodBindingController: NewPodBindingControllerOptions(), DaemonPodUpdaterController: NewDaemonPodUpdaterControllerOptions(), CsrApproverController: NewCsrApproverControllerOptions(), NodePoolController: NewNodePoolControllerOptions(), @@ -61,6 +63,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) { func (y *YurtManagerOptions) Flags(allControllers, disabledByDefaultControllers []string) cliflag.NamedFlagSets { fss := cliflag.NamedFlagSets{} y.Generic.AddFlags(fss.FlagSet("generic"), allControllers, disabledByDefaultControllers) + y.PodBindingController.AddFlags(fss.FlagSet("podbinding controller")) y.DaemonPodUpdaterController.AddFlags(fss.FlagSet("daemonpodupdater controller")) y.CsrApproverController.AddFlags(fss.FlagSet("csrapprover controller")) y.NodePoolController.AddFlags(fss.FlagSet("nodepool controller")) @@ -78,6 +81,7 @@ func (y *YurtManagerOptions) Flags(allControllers, disabledByDefaultControllers func (y *YurtManagerOptions) Validate(allControllers []string, controllerAliases map[string]string) error { var errs []error errs = append(errs, y.Generic.Validate(allControllers, controllerAliases)...) + errs = append(errs, y.PodBindingController.Validate()...) errs = append(errs, y.DaemonPodUpdaterController.Validate()...) errs = append(errs, y.CsrApproverController.Validate()...) errs = append(errs, y.NodePoolController.Validate()...) @@ -95,6 +99,9 @@ func (y *YurtManagerOptions) ApplyTo(c *config.Config, controllerAliases map[str if err := y.Generic.ApplyTo(&c.ComponentConfig.Generic, controllerAliases); err != nil { return err } + if err := y.PodBindingController.ApplyTo(&c.ComponentConfig.PodBindingController); err != nil { + return err + } if err := y.DaemonPodUpdaterController.ApplyTo(&c.ComponentConfig.DaemonPodUpdaterController); err != nil { return err } diff --git a/cmd/yurt-manager/app/options/podbindingcontroller.go b/cmd/yurt-manager/app/options/podbindingcontroller.go new file mode 100644 index 00000000000..409734d266e --- /dev/null +++ b/cmd/yurt-manager/app/options/podbindingcontroller.go @@ -0,0 +1,63 @@ +/* +Copyright 2024 The OpenYurt Authors. + +Licensed under the Apache License, Version 2.0 (the License); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an AS IS BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package options + +import ( + "github.com/spf13/pflag" + + "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtcoordinator/podbinding/config" +) + +type PodBindingControllerOptions struct { + *config.PodBindingControllerConfiguration +} + +func NewPodBindingControllerOptions() *PodBindingControllerOptions { + return &PodBindingControllerOptions{ + &config.PodBindingControllerConfiguration{ + ConcurrentPodBindingWorkers: 5, + }, + } +} + +// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet. +func (n *PodBindingControllerOptions) AddFlags(fs *pflag.FlagSet) { + if n == nil { + return + } + + fs.Int32Var(&n.ConcurrentPodBindingWorkers, "concurrent-podbinding-workers", n.ConcurrentPodBindingWorkers, "The number of podbinding objects that are allowed to reconcile concurrently. Larger number = more responsive podbindings, but more CPU (and network) load") +} + +// ApplyTo fills up nodePool config with options. +func (o *PodBindingControllerOptions) ApplyTo(cfg *config.PodBindingControllerConfiguration) error { + if o == nil { + return nil + } + + cfg.ConcurrentPodBindingWorkers = o.ConcurrentPodBindingWorkers + return nil +} + +// Validate checks validation of DaemonPodUpdaterControllerOptions. +func (o *PodBindingControllerOptions) Validate() []error { + if o == nil { + return nil + } + errs := []error{} + return errs +} diff --git a/pkg/yurtmanager/controller/apis/config/types.go b/pkg/yurtmanager/controller/apis/config/types.go index 2d8809f3896..2cc17471b5f 100644 --- a/pkg/yurtmanager/controller/apis/config/types.go +++ b/pkg/yurtmanager/controller/apis/config/types.go @@ -29,6 +29,7 @@ import ( yurtappdaemonconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtappdaemon/config" yurtappoverriderconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtappoverrider/config" yurtappsetconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtappset/config" + podbindingconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtcoordinator/podbinding/config" yurtstaticsetconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/yurtstaticset/config" ) @@ -37,6 +38,9 @@ type YurtManagerConfiguration struct { metav1.TypeMeta Generic GenericConfiguration + // PodBindingControllerConfiguration holds configuration for PodBindingController related features. + PodBindingController podbindingconfig.PodBindingControllerConfiguration + // DaemonPodUpdaterControllerConfiguration holds configuration for DaemonPodUpdaterController related features. DaemonPodUpdaterController daemonpodupdaterconfig.DaemonPodUpdaterControllerConfiguration diff --git a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/config/types.go b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/config/types.go new file mode 100644 index 00000000000..fef0c007867 --- /dev/null +++ b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/config/types.go @@ -0,0 +1,22 @@ +/* +Copyright 2024 The OpenYurt Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package config + +// PodBindingControllerConfiguration contains elements describing PodBindingController. +type PodBindingControllerConfiguration struct { + ConcurrentPodBindingWorkers int32 +} diff --git a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/podbinding_controller.go b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/podbinding_controller.go index 7527e85695a..b5978a1fd69 100644 --- a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/podbinding_controller.go +++ b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/podbinding_controller.go @@ -18,7 +18,6 @@ package podbinding import ( "context" - "flag" "fmt" appsv1 "k8s.io/api/apps/v1" @@ -37,13 +36,8 @@ import ( nodeutil "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/util/node" ) -func init() { - flag.IntVar(&concurrentReconciles, "podbinding-controller", concurrentReconciles, "Max concurrent workers for podbinding-controller controller.") -} - var ( controllerKind = appsv1.SchemeGroupVersion.WithKind("Node") - concurrentReconciles = 5 defaultTolerationSeconds = 300 notReadyToleration = corev1.Toleration{ @@ -72,7 +66,7 @@ type ReconcilePodBinding struct { // and Start it when the Manager is Started. func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager) error { klog.Infof(Format("podbinding-controller add controller %s", controllerKind.String())) - return add(mgr, newReconciler(c, mgr)) + return add(mgr, c, newReconciler(c, mgr)) } // newReconciler returns a new reconcile.Reconciler @@ -81,9 +75,9 @@ func newReconciler(_ *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 { c, err := controller.New(names.PodBindingController, mgr, controller.Options{ - Reconciler: r, MaxConcurrentReconciles: concurrentReconciles, + Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.PodBindingController.ConcurrentPodBindingWorkers), }) if err != nil { return err