Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve configuration of concurrent daemon pod updater workers (#1907) #1919

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

import (
"context"
"flag"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -55,13 +54,7 @@
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 @@
// 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))

Check warning on line 99 in pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go#L99

Added line #L99 was not covered by tests
}

var _ reconcile.Reconciler = &ReconcileDaemonpodupdater{}
Expand Down Expand Up @@ -140,9 +133,9 @@
}

// 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 {

Check warning on line 136 in pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go#L136

Added line #L136 was not covered by tests
// 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)})

Check warning on line 138 in pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/daemonpodupdater/daemon_pod_updater_controller.go#L138

Added line #L138 was not covered by tests
if err != nil {
return err
}
Expand Down
Loading