Skip to content

Commit

Permalink
improve concurrent workers parameter for service topology endpointsli…
Browse files Browse the repository at this point in the history
…ce controller (#2086)
  • Loading branch information
rambohe-ch authored Jun 26, 2024
1 parent 0007dd0 commit e645696
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 46 deletions.
12 changes: 0 additions & 12 deletions charts/yurt-manager/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,6 @@ kind: ClusterRole
metadata:
name: yurt-manager-service-topology-endpoints-controller
rules:
- apiGroups:
- apps.openyurt.io
resources:
- nodepools
verbs:
- get
- apiGroups:
- ""
resources:
Expand All @@ -841,12 +835,6 @@ kind: ClusterRole
metadata:
name: yurt-manager-service-topology-endpointslice-controller
rules:
- apiGroups:
- apps.openyurt.io
resources:
- nodepools
verbs:
- get
- apiGroups:
- ""
resources:
Expand Down
26 changes: 13 additions & 13 deletions cmd/yurt-manager/app/options/endpointscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/endpoints/config"
)

type EndPointsControllerOptions struct {
*config.ServiceTopologyEndPointsControllerConfiguration
type EndpointsControllerOptions struct {
*config.ServiceTopologyEndpointsControllerConfiguration
}

func NewEndPointsControllerOptions() *EndPointsControllerOptions {
return &EndPointsControllerOptions{
&config.ServiceTopologyEndPointsControllerConfiguration{
ConcurrentEndPointsWorkers: 3,
func NewEndpointsControllerOptions() *EndpointsControllerOptions {
return &EndpointsControllerOptions{
&config.ServiceTopologyEndpointsControllerConfiguration{
ConcurrentEndpointsWorkers: 3,
},
}
}

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

fs.Int32Var(&n.ConcurrentEndPointsWorkers, "servicetopology-endpoints-workers", n.ConcurrentEndPointsWorkers, "Max concurrent workers for Servicetopology-endpoints controller.")
fs.Int32Var(&n.ConcurrentEndpointsWorkers, "concurrent-endpoints-workers", n.ConcurrentEndpointsWorkers, "Max concurrent workers for servicetopology-endpoints controller.")
}

// ApplyTo fils up servicetopolgy endpoints config with options.
func (o *EndPointsControllerOptions) ApplyTo(cfg *config.ServiceTopologyEndPointsControllerConfiguration) error {
// ApplyTo fills up servicetopolgy endpoints config with options.
func (o *EndpointsControllerOptions) ApplyTo(cfg *config.ServiceTopologyEndpointsControllerConfiguration) error {
if o == nil {
return nil
}

cfg.ConcurrentEndPointsWorkers = o.ConcurrentEndPointsWorkers
cfg.ConcurrentEndpointsWorkers = o.ConcurrentEndpointsWorkers
return nil
}

// Validate checks validation of EndPointsControllerOptions.
func (o *EndPointsControllerOptions) Validate() []error {
// Validate checks validation of EndpointsControllerOptions.
func (o *EndpointsControllerOptions) Validate() []error {
if o == nil {
return nil
}
Expand Down
60 changes: 60 additions & 0 deletions cmd/yurt-manager/app/options/endpointslicecontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
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/servicetopology/endpointslice/config"
)

type EndpointSliceControllerOptions struct {
*config.ServiceTopologyEndpointSliceControllerConfiguration
}

func NewEndpointSliceControllerOptions() *EndpointSliceControllerOptions {
return &EndpointSliceControllerOptions{
&config.ServiceTopologyEndpointSliceControllerConfiguration{
ConcurrentEndpointSliceWorkers: 3,
},
}
}

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

fs.Int32Var(&n.ConcurrentEndpointSliceWorkers, "concurrent-endpointslice-workers", n.ConcurrentEndpointSliceWorkers, "Max concurrent workers for servicetopology-endpointslice controller.")
}

// ApplyTo fills up servicetopolgy endpointslice config with options.
func (o *EndpointSliceControllerOptions) ApplyTo(cfg *config.ServiceTopologyEndpointSliceControllerConfiguration) error {
if o == nil {
return nil
}

cfg.ConcurrentEndpointSliceWorkers = o.ConcurrentEndpointSliceWorkers
return nil
}

// Validate checks validation of EndpointSliceControllerOptions.
func (o *EndpointSliceControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
return errs
}
17 changes: 12 additions & 5 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type YurtManagerOptions struct {
YurtAppOverriderController *YurtAppOverriderControllerOptions
NodeLifeCycleController *NodeLifecycleControllerOptions
NodeBucketController *NodeBucketControllerOptions
EndPointsController *EndPointsControllerOptions
EndpointsController *EndpointsControllerOptions
EndpointSliceController *EndpointSliceControllerOptions
LoadBalancerSetController *LoadBalancerSetControllerOptions
}

Expand All @@ -61,7 +62,8 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) {
YurtAppOverriderController: NewYurtAppOverriderControllerOptions(),
NodeLifeCycleController: NewNodeLifecycleControllerOptions(),
NodeBucketController: NewNodeBucketControllerOptions(),
EndPointsController: NewEndPointsControllerOptions(),
EndpointsController: NewEndpointsControllerOptions(),
EndpointSliceController: NewEndpointSliceControllerOptions(),
LoadBalancerSetController: NewLoadBalancerSetControllerOptions(),
}

Expand All @@ -83,7 +85,8 @@ func (y *YurtManagerOptions) Flags(allControllers, disabledByDefaultControllers
y.YurtAppOverriderController.AddFlags(fss.FlagSet("yurtappoverrider controller"))
y.NodeLifeCycleController.AddFlags(fss.FlagSet("nodelifecycle controller"))
y.NodeBucketController.AddFlags(fss.FlagSet("nodebucket controller"))
y.EndPointsController.AddFlags(fss.FlagSet("endpoints controller"))
y.EndpointsController.AddFlags(fss.FlagSet("endpoints controller"))
y.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
y.LoadBalancerSetController.AddFlags(fss.FlagSet("loadbalancerset controller"))
return fss
}
Expand All @@ -104,7 +107,8 @@ func (y *YurtManagerOptions) Validate(allControllers []string, controllerAliases
errs = append(errs, y.YurtAppOverriderController.Validate()...)
errs = append(errs, y.NodeLifeCycleController.Validate()...)
errs = append(errs, y.NodeBucketController.Validate()...)
errs = append(errs, y.EndPointsController.Validate()...)
errs = append(errs, y.EndpointsController.Validate()...)
errs = append(errs, y.EndpointSliceController.Validate()...)
errs = append(errs, y.LoadBalancerSetController.Validate()...)
return utilerrors.NewAggregate(errs)
}
Expand Down Expand Up @@ -150,7 +154,10 @@ func (y *YurtManagerOptions) ApplyTo(c *config.Config, controllerAliases map[str
if err := y.NodeBucketController.ApplyTo(&c.ComponentConfig.NodeBucketController); err != nil {
return err
}
if err := y.EndPointsController.ApplyTo(&c.ComponentConfig.ServiceTopologyEndpointsController); err != nil {
if err := y.EndpointsController.ApplyTo(&c.ComponentConfig.ServiceTopologyEndpointsController); err != nil {
return err
}
if err := y.EndpointSliceController.ApplyTo(&c.ComponentConfig.ServiceTopologyEndpointSliceController); err != nil {
return err
}
if err := y.LoadBalancerSetController.ApplyTo(&c.ComponentConfig.LoadBalancerSetController); err != nil {
Expand Down
8 changes: 6 additions & 2 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 (
platformadminconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config"
gatewaypickupconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/gatewaypickup/config"
endpointsconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/endpoints/config"
endpointsliceconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/endpointslice/config"
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"
Expand Down Expand Up @@ -80,8 +81,11 @@ type YurtManagerConfiguration struct {
// NodeBucketController holds configuration for NodeBucketController related features.
NodeBucketController nodebucketconfig.NodeBucketControllerConfiguration

// EndPointsController holds configuration for EndPointsController related features.
ServiceTopologyEndpointsController endpointsconfig.ServiceTopologyEndPointsControllerConfiguration
// EndpointsController holds configuration for EndpointsController related features.
ServiceTopologyEndpointsController endpointsconfig.ServiceTopologyEndpointsControllerConfiguration

// EndpointSliceController holds configuration for EndpointSliceController related features.
ServiceTopologyEndpointSliceController endpointsliceconfig.ServiceTopologyEndpointSliceControllerConfiguration

// LoadBalancerSetController holds configuration for LoadBalancerSetController related features.
LoadBalancerSetController loadbalancersetconfig.LoadBalancerSetControllerConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ limitations under the License.

package config

// EndPointsControllerConfiguration contains elements describing EndPOintsController
type ServiceTopologyEndPointsControllerConfiguration struct {
ConcurrentEndPointsWorkers int32
// ServiceTopologyEndpointsControllerConfiguration contains elements describing EndpointsController
type ServiceTopologyEndpointsControllerConfiguration struct {
ConcurrentEndpointsWorkers int32
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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, cfg *appconfig.CompletedConfig, r reconcile.Reconciler) error {
// Create a new controller
c, err := controller.New(names.ServiceTopologyEndpointsController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.ServiceTopologyEndpointsController.ConcurrentEndPointsWorkers)})
c, err := controller.New(names.ServiceTopologyEndpointsController, mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.ServiceTopologyEndpointsController.ConcurrentEndpointsWorkers)})
if err != nil {
return err
}
Expand All @@ -86,7 +86,6 @@ func add(mgr manager.Manager, cfg *appconfig.CompletedConfig, r reconcile.Reconc
}

// +kubebuilder:rbac:groups=core,resources=services,verbs=get
// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepools,verbs=get
// +kubebuilder:rbac:groups=core,resources=endpoints,verbs=get;patch

// Reconcile reads that state of the cluster for endpoints object and makes changes based on the state read
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
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

// ServiceTopologyEndpointSliceControllerConfiguration contains elements describing EndpointSliceController
type ServiceTopologyEndpointSliceControllerConfiguration struct {
ConcurrentEndpointSliceWorkers int32
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package endpointslice

import (
"context"
"flag"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand All @@ -38,13 +37,8 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/adapter"
)

func init() {
flag.IntVar(&concurrentReconciles, "servicetopology-endpointslice-workers", concurrentReconciles, "Max concurrent workers for Servicetopology-endpointslice controller.")
}

var (
concurrentReconciles = 3
v1EndpointSliceGVR = discoveryv1.SchemeGroupVersion.WithResource("endpointslices")
v1EndpointSliceGVR = discoveryv1.SchemeGroupVersion.WithResource("endpointslices")
)

func Format(format string, args ...interface{}) string {
Expand All @@ -57,7 +51,7 @@ func Format(format string, args ...interface{}) string {
func Add(ctx context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manager) error {
r := newReconciler(cfg, mgr)
c, err := controller.New(names.ServiceTopologyEndpointSliceController, mgr,
controller.Options{Reconciler: r, MaxConcurrentReconciles: concurrentReconciles})
controller.Options{Reconciler: r, MaxConcurrentReconciles: int(cfg.ComponentConfig.ServiceTopologyEndpointSliceController.ConcurrentEndpointSliceWorkers)})
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +94,6 @@ func newReconciler(_ *appconfig.CompletedConfig, mgr manager.Manager) *Reconcile
}

// +kubebuilder:rbac:groups=core,resources=services,verbs=get
// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepools,verbs=get
// +kubebuilder:rbac:groups=discovery.k8s.io,resources=endpointslices,verbs=get;patch

// Reconcile reads that state of the cluster for endpointslice object and makes changes based on the state read
Expand Down

0 comments on commit e645696

Please sign in to comment.