Skip to content

Commit

Permalink
feat: improve configuration of concurrent pod-binding workers (openyu…
Browse files Browse the repository at this point in the history
…rtio#1917) (openyurtio#1923)

Signed-off-by: Chenzhao Huang <[email protected]>
  • Loading branch information
huangchenzhao authored Jan 16, 2024
1 parent 380ea01 commit 81d21b7
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 9 deletions.
7 changes: 7 additions & 0 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,6 +44,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) {

s := YurtManagerOptions{
Generic: NewGenericOptions(),
PodBindingController: NewPodBindingControllerOptions(),
DaemonPodUpdaterController: NewDaemonPodUpdaterControllerOptions(),
CsrApproverController: NewCsrApproverControllerOptions(),
NodePoolController: NewNodePoolControllerOptions(),
Expand All @@ -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"))
Expand All @@ -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()...)
Expand All @@ -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
}
Expand Down
63 changes: 63 additions & 0 deletions cmd/yurt-manager/app/options/podbindingcontroller.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions pkg/yurtmanager/controller/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package podbinding

import (
"context"
"flag"
"fmt"

appsv1 "k8s.io/api/apps/v1"
Expand All @@ -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{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 81d21b7

Please sign in to comment.