From 458060a11a499068a08837d7096c7e8c06bd384d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=A8=E7=BA=A2=E5=B0=98=E4=B8=AD=E6=88=90=E4=BB=99?= <1178404986@qq.com> Date: Fri, 12 Apr 2024 11:19:15 +0800 Subject: [PATCH] 1909 (#2016) * feat: improve configuration of concurrent platform administration workers Co-authored-by: Jiazhen Xu <12321223@zju.edu.cn> --- .../app/options/platformadmincontroller.go | 2 ++ .../controller/platformadmin/config/config.go | 22 ++++++++++--------- .../platformadmin/platformadmin_controller.go | 14 ++++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cmd/yurt-manager/app/options/platformadmincontroller.go b/cmd/yurt-manager/app/options/platformadmincontroller.go index a77a3c231fb..43daa07e603 100644 --- a/cmd/yurt-manager/app/options/platformadmincontroller.go +++ b/cmd/yurt-manager/app/options/platformadmincontroller.go @@ -39,6 +39,8 @@ func (n *PlatformAdminControllerOptions) AddFlags(fs *pflag.FlagSet) { if n == nil { return } + + fs.Int32Var(&n.ConcurrentPlatformAdminWorkers, "concurrent-platform-administrator-workers", n.ConcurrentPlatformAdminWorkers, "Max concurrent workers for PlatformAdmin controller.") } // ApplyTo fills up nodePool config with options. diff --git a/pkg/yurtmanager/controller/platformadmin/config/config.go b/pkg/yurtmanager/controller/platformadmin/config/config.go index bc067613b48..378082d0b7c 100644 --- a/pkg/yurtmanager/controller/platformadmin/config/config.go +++ b/pkg/yurtmanager/controller/platformadmin/config/config.go @@ -88,11 +88,12 @@ func ExtractRequiredComponentsName(manifest *Manifest, versionName string) sets. // PlatformAdminControllerConfiguration contains elements describing PlatformAdminController. type PlatformAdminControllerConfiguration struct { - Manifest Manifest - SecurityComponents map[string][]*Component - NoSectyComponents map[string][]*Component - SecurityConfigMaps map[string][]corev1.ConfigMap - NoSectyConfigMaps map[string][]corev1.ConfigMap + Manifest Manifest + SecurityComponents map[string][]*Component + NoSectyComponents map[string][]*Component + SecurityConfigMaps map[string][]corev1.ConfigMap + NoSectyConfigMaps map[string][]corev1.ConfigMap + ConcurrentPlatformAdminWorkers int32 } func NewPlatformAdminControllerConfiguration() *PlatformAdminControllerConfiguration { @@ -100,11 +101,12 @@ func NewPlatformAdminControllerConfiguration() *PlatformAdminControllerConfigura edgexconfig = EdgeXConfig{} edgexnosectyconfig = EdgeXConfig{} conf = PlatformAdminControllerConfiguration{ - Manifest: Manifest{}, - SecurityComponents: make(map[string][]*Component), - NoSectyComponents: make(map[string][]*Component), - SecurityConfigMaps: make(map[string][]corev1.ConfigMap), - NoSectyConfigMaps: make(map[string][]corev1.ConfigMap), + Manifest: Manifest{}, + SecurityComponents: make(map[string][]*Component), + NoSectyComponents: make(map[string][]*Component), + SecurityConfigMaps: make(map[string][]corev1.ConfigMap), + NoSectyConfigMaps: make(map[string][]corev1.ConfigMap), + ConcurrentPlatformAdminWorkers: 3, } ) diff --git a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go index cac721d0e63..fbec9a2d8cb 100644 --- a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go +++ b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go @@ -19,7 +19,6 @@ package platformadmin import ( "context" "encoding/json" - "flag" "fmt" "time" @@ -54,18 +53,13 @@ import ( util "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/utils" ) -func init() { - flag.IntVar(&concurrentReconciles, "platformadmin-workers", concurrentReconciles, "Max concurrent workers for PlatformAdmin controller.") -} - func Format(format string, args ...interface{}) string { s := fmt.Sprintf(format, args...) return fmt.Sprintf("%s: %s", names.PlatformAdminController, s) } var ( - concurrentReconciles = 3 - controllerResource = iotv1alpha2.SchemeGroupVersion.WithResource("platformadmins") + controllerResource = iotv1alpha2.SchemeGroupVersion.WithResource("platformadmins") ) const ( @@ -126,7 +120,7 @@ func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager) } klog.Infof("platformadmin-controller add controller %s", controllerResource.String()) - return add(mgr, newReconciler(c, mgr)) + return add(mgr, c, newReconciler(c, mgr)) } // newReconciler returns a new reconcile.Reconciler @@ -141,10 +135,10 @@ 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.PlatformAdminController, mgr, controller.Options{ - Reconciler: r, MaxConcurrentReconciles: concurrentReconciles, + Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.PlatformAdminController.ConcurrentPlatformAdminWorkers), }) if err != nil { return err