Skip to content

Commit

Permalink
feat: improve configuration of concurrent daemon pod updater workers (o…
Browse files Browse the repository at this point in the history
…penyurtio#1907) (openyurtio#1919)

Signed-off-by: Chenzhao Huang <[email protected]>
  • Loading branch information
huangchenzhao authored and zyjhtangtang committed Apr 16, 2024
1 parent 6de2a30 commit 0b52121
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 10 deletions.
63 changes: 63 additions & 0 deletions cmd/yurt-manager/app/options/daemonpodupdatercontroller.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/daemonpodupdater/config"
)

type DaemonPodUpdaterControllerOptions struct {
*config.DaemonPodUpdaterControllerConfiguration
}

func NewDaemonPodUpdaterControllerOptions() *DaemonPodUpdaterControllerOptions {
return &DaemonPodUpdaterControllerOptions{
&config.DaemonPodUpdaterControllerConfiguration{
ConcurrentDaemonPodUpdaterWorkers: 3,
},
}
}

// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (n *DaemonPodUpdaterControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
}

fs.Int32Var(&n.ConcurrentDaemonPodUpdaterWorkers, "concurrent-daemonpod-updater-workers", n.ConcurrentDaemonPodUpdaterWorkers, "The number of daemonpodupdater objects that are allowed to reconcile concurrently. Larger number = more responsive daemonpodupdaters, but more CPU (and network) load")
}

// ApplyTo fills up nodePool config with options.
func (o *DaemonPodUpdaterControllerOptions) ApplyTo(cfg *config.DaemonPodUpdaterControllerConfiguration) error {
if o == nil {
return nil
}

cfg.ConcurrentDaemonPodUpdaterWorkers = o.ConcurrentDaemonPodUpdaterWorkers
return nil
}

// Validate checks validation of DaemonPodUpdaterControllerOptions.
func (o *DaemonPodUpdaterControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
return errs
}
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
DaemonPodUpdaterController *DaemonPodUpdaterControllerOptions
CsrApproverController *CsrApproverControllerOptions
NodePoolController *NodePoolControllerOptions
GatewayPickupController *GatewayPickupControllerOptions
Expand All @@ -42,6 +43,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) {

s := YurtManagerOptions{
Generic: NewGenericOptions(),
DaemonPodUpdaterController: NewDaemonPodUpdaterControllerOptions(),
CsrApproverController: NewCsrApproverControllerOptions(),
NodePoolController: NewNodePoolControllerOptions(),
GatewayPickupController: NewGatewayPickupControllerOptions(),
Expand All @@ -59,6 +61,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.DaemonPodUpdaterController.AddFlags(fss.FlagSet("daemonpodupdater controller"))
y.CsrApproverController.AddFlags(fss.FlagSet("csrapprover controller"))
y.NodePoolController.AddFlags(fss.FlagSet("nodepool controller"))
y.GatewayPickupController.AddFlags(fss.FlagSet("gateway controller"))
Expand All @@ -75,6 +78,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.DaemonPodUpdaterController.Validate()...)
errs = append(errs, y.CsrApproverController.Validate()...)
errs = append(errs, y.NodePoolController.Validate()...)
errs = append(errs, y.GatewayPickupController.Validate()...)
Expand All @@ -91,6 +95,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.DaemonPodUpdaterController.ApplyTo(&c.ComponentConfig.DaemonPodUpdaterController); err != nil {
return err
}
if err := y.CsrApproverController.ApplyTo(&c.ComponentConfig.CsrApproverController); err != nil {
return err
}
Expand Down
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 @@ -22,6 +22,7 @@ import (
"k8s.io/kube-controller-manager/config/v1alpha1"

csrapproverconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/csrapprover/config"
daemonpodupdaterconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/daemonpodupdater/config"
nodepoolconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodepool/config"
platformadminconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config"
gatewaypickupconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/gatewaypickup/config"
Expand All @@ -36,6 +37,9 @@ type YurtManagerConfiguration struct {
metav1.TypeMeta
Generic GenericConfiguration

// DaemonPodUpdaterControllerConfiguration holds configuration for DaemonPodUpdaterController related features.
DaemonPodUpdaterController daemonpodupdaterconfig.DaemonPodUpdaterControllerConfiguration

// CsrApproverControllerConfiguration holds configuration for CsrApproverController related features.
CsrApproverController csrapproverconfig.CsrApproverControllerConfiguration

Expand Down
22 changes: 22 additions & 0 deletions pkg/yurtmanager/controller/daemonpodupdater/config/types.go
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

// DaemonPodUpdaterControllerConfiguration contains elements describing DaemonPodUpdaterController.
type DaemonPodUpdaterControllerConfiguration struct {
ConcurrentDaemonPodUpdaterWorkers int32
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package daemonpodupdater

import (
"context"
"flag"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -55,13 +54,7 @@ import (
podutil "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/util/pod"
)

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

var (
concurrentReconciles = 3

// controllerKind contains the schema.GroupVersionKind for this controller type.
controllerKind = appsv1.SchemeGroupVersion.WithKind("DaemonSet")
)
Expand Down Expand Up @@ -103,7 +96,7 @@ func Format(format string, args ...interface{}) string {
// and Start it when the Manager is Started.
func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager) error {
klog.Infof("daemonupdater-controller add controller %s", controllerKind.String())
return add(mgr, newReconciler(c, mgr))
return add(mgr, c, newReconciler(c, mgr))
}

var _ reconcile.Reconciler = &ReconcileDaemonpodupdater{}
Expand Down Expand Up @@ -140,9 +133,9 @@ func (r *ReconcileDaemonpodupdater) InjectConfig(cfg *rest.Config) error {
}

// 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.DaemonPodUpdaterController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: concurrentReconciles})
c, err := controller.New(names.DaemonPodUpdaterController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: int(cfg.Config.ComponentConfig.DaemonPodUpdaterController.ConcurrentDaemonPodUpdaterWorkers)})
if err != nil {
return err
}
Expand Down

0 comments on commit 0b52121

Please sign in to comment.