Skip to content

Commit

Permalink
fix: add qps and burst
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu_yewu <[email protected]>
  • Loading branch information
renxiangyu_yewu committed Dec 11, 2024
1 parent 5539314 commit 82dd571
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 97 deletions.
6 changes: 3 additions & 3 deletions charts/kosmos/templates/07-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec:
containers:
- command:
- kosmos-operator
- --controlpanelconfig=/etc/kosmos-operator/kubeconfig
- --controlpanel-kubeconfig=/etc/kosmos-operator/kubeconfig
env:
- name: VERSION
value: {{ .Values.operator.image.tag }}
Expand Down Expand Up @@ -280,7 +280,7 @@ spec:
containers:
- command:
- clusterlink-elector
- --controlpanelconfig=/etc/clusterlink/kubeconfig
- --controlpanel-kubeconfig=/etc/clusterlink/kubeconfig
- --v=3
env:
- name: CLUSTER_NAME
Expand Down Expand Up @@ -360,7 +360,7 @@ spec:
containers:
- command:
- clusterlink-controller-manager
- --controlpanelconfig=/etc/clusterlink/kubeconfig
- --controlpanel-kubeconfig=/etc/clusterlink/kubeconfig
env:
- name: CLUSTER_NAME
value: kosmos-control-cluster
Expand Down
3 changes: 2 additions & 1 deletion cmd/clusterlink/agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ func NewAgentCommand(ctx context.Context) *cobra.Command {
}

func run(ctx context.Context, opts *options.Options) error {
restConfig, err := clientcmd.BuildConfigFromFlags("", opts.KubeConfig)
restConfig, err := clientcmd.BuildConfigFromFlags(opts.KubernetesOptions.MasterURL, opts.KubernetesOptions.KubeConfig)
if err != nil {
return fmt.Errorf("error building kubeconfig: %s", err.Error())
}
utils.SetQPSBurst(restConfig, opts.KubernetesOptions)

if err = network.CreateGlobalNetIptablesChains(); err != nil {
return fmt.Errorf("failed to create clusterlink iptables chains: %s", err.Error())
Expand Down
13 changes: 8 additions & 5 deletions cmd/clusterlink/agent/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"time"

"github.com/spf13/pflag"

"github.com/kosmos.io/kosmos/pkg/utils"
)

type Options struct {
KubeConfig string
KubernetesOptions utils.KubernetesOptions

// CleanPeriod represents clusterlink-agent cleanup period
CleanPeriod time.Duration
}

// NewOptions builds a default agent options.
func NewOptions() *Options {
return &Options{
KubeConfig: "",
}
return &Options{}
}

// AddFlags adds flags of agent to the specified FlagSet
Expand All @@ -26,6 +26,9 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
return
}

fs.StringVar(&o.KubeConfig, "kubeconfig", o.KubeConfig, "Path to control plane kubeconfig file.")
fs.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", utils.DefaultKubeQPS, "QPS to use while talking with kube-apiserver.")
fs.IntVar(&o.KubernetesOptions.Burst, "kube-burst", utils.DefaultKubeBurst, "Burst to use while talking with kube-apiserver.")
fs.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path to control plane kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.MasterURL, "master-url", "", "Used to generate kubeconfig for downloading, if not specified, will use host in control plane kubeconfig.")
fs.DurationVar(&o.CleanPeriod, "clean-period", 30*time.Second, "Specifies how often the agent cleans up routes and network interface.")
}
11 changes: 7 additions & 4 deletions cmd/clusterlink/clusterlink-operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,20 @@ func NewLinkOperatorCommand(ctx context.Context) *cobra.Command {
}

func Run(ctx context.Context, opts *options.Options) error {
restConfig, err := clientcmd.BuildConfigFromFlags("", opts.KubeConfig)
restConfig, err := clientcmd.BuildConfigFromFlags(opts.KubernetesOptions.MasterURL, opts.KubernetesOptions.KubeConfig)
if err != nil {
return fmt.Errorf("error building kubeconfig: %s", err.Error())
}
utils.SetQPSBurst(restConfig, opts.KubernetesOptions)

clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return fmt.Errorf("error get kubeclient: %v", err)
}

var controlPanelKubeConfig *clientcmdapi.Config
if len(opts.ControlPanelKubeConfig) > 0 {
controlPanelKubeConfig, err = clientcmd.LoadFromFile(opts.ControlPanelKubeConfig)
if len(opts.KubernetesOptions.ControlpanelKubeConfig) > 0 {
controlPanelKubeConfig, err = clientcmd.LoadFromFile(opts.KubernetesOptions.ControlpanelKubeConfig)
if err != nil {
return fmt.Errorf("failed to load controlpanelKubeConfig: %v", err)
}
Expand All @@ -100,10 +102,11 @@ func Run(ctx context.Context, opts *options.Options) error {
controlPanelKubeConfig = config
}

c, err := clientcmd.BuildConfigFromFlags("", opts.ControlPanelKubeConfig)
c, err := clientcmd.BuildConfigFromFlags(opts.KubernetesOptions.ControlpanelMasterURL, opts.KubernetesOptions.ControlpanelKubeConfig)
if err != nil {
return fmt.Errorf("error building kubeconfig: %s", err.Error())
}
utils.SetQPSBurst(c, opts.KubernetesOptions)
mgr, err := ctrl.NewManager(c, ctrl.Options{
Scheme: scheme.NewSchema(),
})
Expand Down
18 changes: 11 additions & 7 deletions cmd/clusterlink/clusterlink-operator/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ package options

import (
"github.com/spf13/pflag"

"github.com/kosmos.io/kosmos/pkg/utils"
)

type Options struct {
KubeConfig string
ControlPanelKubeConfig string
KubernetesOptions utils.KubernetesOptions
ExternalKubeConfigName string
UseProxy bool
}

// NewOptions builds a default agent options.
func NewOptions() *Options {
return &Options{
KubeConfig: "",
}
return &Options{}
}

// AddFlags adds flags of estimator to the specified FlagSet
func (o *Options) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}
fs.StringVar(&o.KubeConfig, "kubeconfig", "", "Path to control plane kubeconfig file.")
fs.StringVar(&o.ControlPanelKubeConfig, "controlpanelconfig", "", "Path to host control plane kubeconfig file.")

fs.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", utils.DefaultKubeQPS, "QPS to use while talking with kube-apiserver.")
fs.IntVar(&o.KubernetesOptions.Burst, "kube-burst", utils.DefaultKubeBurst, "Burst to use while talking with kube-apiserver.")
fs.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path to host kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.MasterURL, "master-url", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
fs.StringVar(&o.KubernetesOptions.ControlpanelKubeConfig, "controlpanel-kubeconfig", "", "Path to control plane kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.ControlpanelMasterURL, "controlpanel-master-url", "", "Used to generate host control plane kubeconfig for downloading, if not specified, will use host in controlpanel-kubeconfig.")
fs.StringVar(&o.ExternalKubeConfigName, "ExternalKubeConfigName", "external-kubeconfig", "external kube config name.")
fs.BoolVar(&o.UseProxy, "UseProxy", false, "external kube config name.")
}
9 changes: 7 additions & 2 deletions cmd/clusterlink/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned"
"github.com/kosmos.io/kosmos/pkg/scheme"
"github.com/kosmos.io/kosmos/pkg/sharedcli/klogflag"
"github.com/kosmos.io/kosmos/pkg/utils"
)

var (
Expand Down Expand Up @@ -80,6 +81,8 @@ func Run(ctx context.Context, opts *options.ControllerManagerOptions) error {
panic(err)
}

utils.SetQPSBurst(config, opts.KubernetesOptions)

controllerManager, err := ctrl.NewManager(config, ctrl.Options{
Scheme: scheme.NewSchema(),
})
Expand All @@ -89,11 +92,12 @@ func Run(ctx context.Context, opts *options.ControllerManagerOptions) error {
}

//TODO 整理这块
controlPanelConfig, err := clientcmd.BuildConfigFromFlags("", opts.ControlPanelConfig)
controlPanelConfig, err := clientcmd.BuildConfigFromFlags(opts.ControlpanelMasterURL, opts.ControlpanelKubeConfig)
if err != nil {
klog.Fatalf("build controlpanel config err: %v", err)
panic(err)
}
utils.SetQPSBurst(controlPanelConfig, opts.KubernetesOptions)

clusterLinkClient, err := versioned.NewForConfig(controlPanelConfig)
if err != nil {
Expand All @@ -111,11 +115,12 @@ func Run(ctx context.Context, opts *options.ControllerManagerOptions) error {
}

func setupControllers(ctx context.Context, mgr ctrl.Manager, opts *options.ControllerManagerOptions) []ctrlcontext.CleanFunc {
controlPanelConfig, err := clientcmd.BuildConfigFromFlags("", opts.ControlPanelConfig)
controlPanelConfig, err := clientcmd.BuildConfigFromFlags(opts.ControlpanelMasterURL, opts.ControlpanelKubeConfig)
if err != nil {
klog.Fatalf("build controlpanel config err: %v", err)
panic(err)
}
utils.SetQPSBurst(controlPanelConfig, opts.KubernetesOptions)

clusterLinkClient, err := versioned.NewForConfig(controlPanelConfig)
if err != nil {
Expand Down
14 changes: 9 additions & 5 deletions cmd/clusterlink/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ type ControllerManagerOptions struct {

RateLimiterOpts lifted.RateLimitOptions

ControlPanelConfig string

KubeConfig string

ClusterName string

utils.KubernetesOptions
}

// NewControllerManagerOptions builds a default controller manager options.
Expand All @@ -36,10 +34,16 @@ func (o *ControllerManagerOptions) Validate() field.ErrorList {
}

func (o *ControllerManagerOptions) AddFlags(fs *pflag.FlagSet, allControllers, disabledByDefaultControllers []string) {
fs.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", utils.DefaultKubeQPS, "QPS to use while talking with kube-apiserver.")
fs.IntVar(&o.KubernetesOptions.Burst, "kube-burst", utils.DefaultKubeBurst, "Burst to use while talking with kube-apiserver.")
fs.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path to host kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.MasterURL, "master-url", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
fs.StringVar(&o.KubernetesOptions.ControlpanelKubeConfig, "controlpanel-kubeconfig", "", "Path to control plane kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.ControlpanelMasterURL, "controlpanel-master-url", "", "Used to generate host control plane kubeconfig for downloading, if not specified, will use host in control panel kubeconfig.")

fs.StringSliceVar(&o.Controllers, "controllers", []string{"*"}, fmt.Sprintf(
"A list of controllers to enable. '*' enables all on-by-default controllers, 'foo' enables the controller named 'foo', '-foo' disables the controller named 'foo'. \nAll controllers: %s.\nDisabled-by-default controllers: %s",
strings.Join(allControllers, ", "), strings.Join(disabledByDefaultControllers, ", "),
))
fs.StringVar(&o.ClusterName, "cluster", os.Getenv(utils.EnvClusterName), "current cluster name.")
fs.StringVar(&o.ControlPanelConfig, "controlpanelconfig", "", "path to controlpanel kubeconfig file.")
}
8 changes: 6 additions & 2 deletions cmd/clusterlink/elector/app/elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned"
"github.com/kosmos.io/kosmos/pkg/sharedcli"
"github.com/kosmos.io/kosmos/pkg/sharedcli/klogflag"
"github.com/kosmos.io/kosmos/pkg/utils"
)

// NewElectorCommand creates a *cobra.Command object with default parameters
Expand Down Expand Up @@ -71,15 +72,18 @@ func NewElectorCommand(ctx context.Context) *cobra.Command {
}

func run(ctx context.Context, opts *options.Options) error {
memberClusterConfig, err := clientcmd.BuildConfigFromFlags("", opts.KubeConfig)
memberClusterConfig, err := clientcmd.BuildConfigFromFlags(opts.MasterURL, opts.KubeConfig)
if err != nil {
return fmt.Errorf("error building kubeconfig: %+v", err)
}
utils.SetQPSBurst(memberClusterConfig, opts.KubernetesOptions)

controlpanelConfig, err := clientcmd.BuildConfigFromFlags("", opts.ControlPanelConfig)
controlpanelConfig, err := clientcmd.BuildConfigFromFlags(opts.ControlpanelMasterURL, opts.ControlpanelKubeConfig)
if err != nil {
return fmt.Errorf("error building controlpanelConfig: %+v", err)
}
utils.SetQPSBurst(controlpanelConfig, opts.KubernetesOptions)

controlpanelClient, err := versioned.NewForConfig(controlpanelConfig)
if err != nil {
return fmt.Errorf("error building controlpanelClient: %+v", err)
Expand Down
17 changes: 10 additions & 7 deletions cmd/clusterlink/elector/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ var (
)

type Options struct {
LeaderElection componentbaseconfig.LeaderElectionConfiguration
KubeConfig string
ControlPanelConfig string
LeaderElection componentbaseconfig.LeaderElectionConfiguration
utils.KubernetesOptions
}

// NewOptions builds a default elector options.
Expand All @@ -39,13 +38,19 @@ func NewOptions() *Options {
func (o *Options) Validate() field.ErrorList {
errs := field.ErrorList{}
newPath := field.NewPath("Options")
if len(o.ControlPanelConfig) == 0 {
errs = append(errs, field.Invalid(newPath.Child("controlpanelconfig"), o.ControlPanelConfig, "controlpanelconfig path should not empty"))
if len(o.KubernetesOptions.ControlpanelKubeConfig) == 0 {
errs = append(errs, field.Invalid(newPath.Child("controlpanelconfig"), o.ControlpanelKubeConfig, "controlpanelconfig path should not empty"))
}
return errs
}

func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", utils.DefaultKubeQPS, "QPS to use while talking with kube-apiserver.")
fs.IntVar(&o.KubernetesOptions.Burst, "kube-burst", utils.DefaultKubeBurst, "Burst to use while talking with kube-apiserver.")
fs.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path to host kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.MasterURL, "master-url", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
fs.StringVar(&o.KubernetesOptions.ControlpanelKubeConfig, "controlpanel-kubeconfig", "", "Path to control plane kubeconfig file.")
fs.StringVar(&o.KubernetesOptions.ControlpanelMasterURL, "controlpanel-master-url", "", "Used to generate host control plane kubeconfig for downloading, if not specified, will use host in controlpanel-kubeconfig.")
fs.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Enable leader election, which must be true when running multi instances.")
fs.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "elector", "The name of resource object that is used for locking during leader election.")
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
Expand All @@ -62,6 +67,4 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.DurationVar(&o.LeaderElection.RetryPeriod.Duration, "leader-elect-retry-period", defaultElectionRetryPeriod.Duration, ""+
"The duration the clients should wait between attempting acquisition and renewal "+
"of a leadership. This is only applicable if leader election is enabled.")
fs.StringVar(&o.KubeConfig, "kubeconfig", "", "path to elector kubeconfig file.")
fs.StringVar(&o.ControlPanelConfig, "controlpanelconfig", "", "path to controlpanel kubeconfig file.")
}
2 changes: 1 addition & 1 deletion cmd/clusterlink/floater/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Options struct {
KubeConfig string

// CleanPeriod represents clusterlink-agent cleanup period
// CleanPeriod represents clusterlink-floater cleanup period
CleanPeriod time.Duration
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterlink/network-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
networkmanager "github.com/kosmos.io/kosmos/pkg/clusterlink/network-manager"
"github.com/kosmos.io/kosmos/pkg/scheme"
"github.com/kosmos.io/kosmos/pkg/sharedcli/klogflag"
"github.com/kosmos.io/kosmos/pkg/utils"
)

func NewNetworkManagerCommand(ctx context.Context) *cobra.Command {
Expand Down Expand Up @@ -45,11 +46,11 @@ func NewNetworkManagerCommand(ctx context.Context) *cobra.Command {
}

func run(ctx context.Context, opts *options.Options) error {
config, err := clientcmd.BuildConfigFromFlags(opts.KubernetesOptions.Master, opts.KubernetesOptions.KubeConfig)
config, err := clientcmd.BuildConfigFromFlags(opts.KubernetesOptions.MasterURL, opts.KubernetesOptions.KubeConfig)
if err != nil {
panic(err)
}
config.QPS, config.Burst = opts.KubernetesOptions.QPS, opts.KubernetesOptions.Burst
utils.SetQPSBurst(config, opts.KubernetesOptions)

mgr, err := controllerruntime.NewManager(config, controllerruntime.Options{
Logger: klog.Background(),
Expand Down
19 changes: 6 additions & 13 deletions cmd/clusterlink/network-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ import (
)

type Options struct {
LeaderElection componentbaseconfig.LeaderElectionConfiguration
KubernetesOptions KubernetesOptions
}

type KubernetesOptions struct {
KubeConfig string `json:"kubeconfig" yaml:"kubeconfig"`
Master string `json:"master,omitempty" yaml:"master,omitempty"`
QPS float32 `json:"qps,omitempty" yaml:"qps,omitempty"`
Burst int `json:"burst,omitempty" yaml:"burst,omitempty"`
LeaderElection componentbaseconfig.LeaderElectionConfiguration
utils.KubernetesOptions
}

func NewOptions() *Options {
Expand All @@ -39,8 +32,8 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
flags.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "network-manager", "The name of resource object that is used for locking during leader election.")
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
flags.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", 40.0, "QPS to use while talking with kube-apiserver.")
flags.IntVar(&o.KubernetesOptions.Burst, "kube-burst", 60, "Burst to use while talking with kube-apiserver.")
flags.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path for kubernetes kubeconfig file, if left blank, will use in cluster way.")
flags.StringVar(&o.KubernetesOptions.Master, "master", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
flags.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", utils.DefaultTreeAndNetManagerKubeQPS, "QPS to use while talking with kube-apiserver.")
flags.IntVar(&o.KubernetesOptions.Burst, "kube-burst", utils.DefaultTreeAndNetManagerKubeBurst, "Burst to use while talking with kube-apiserver.")
flags.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path to host kubeconfig file.")
flags.StringVar(&o.KubernetesOptions.MasterURL, "master-url", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
}
Loading

0 comments on commit 82dd571

Please sign in to comment.