Skip to content

Commit

Permalink
1909 (#2016)
Browse files Browse the repository at this point in the history
* feat: improve configuration of concurrent platform administration workers

Co-authored-by: Jiazhen Xu <[email protected]>
  • Loading branch information
MundaneImmortal and Jiazhen Xu authored Apr 12, 2024
1 parent 839a52a commit 458060a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 2 additions & 0 deletions cmd/yurt-manager/app/options/platformadmincontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions pkg/yurtmanager/controller/platformadmin/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,25 @@ 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 {
var (
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,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package platformadmin
import (
"context"
"encoding/json"
"flag"
"fmt"
"time"

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 458060a

Please sign in to comment.