From 8895d51c685cb8e5fcd68b32cb37ef6e1be8cccc Mon Sep 17 00:00:00 2001 From: Benjamin Alpert Date: Tue, 26 Nov 2024 15:34:51 +0100 Subject: [PATCH] change poollet client specific qps and burst opts implementation to common options pattern --- .../cmd/bucketpoollet/app/app.go | 7 ---- poollet/common/defaults/defaults.go | 9 ----- .../cmd/machinepoollet/app/app.go | 7 ---- .../cmd/volumepoollet/app/app.go | 7 ---- utils/client/config/config.go | 14 ++++++-- utils/client/config/options.go | 33 ++++++++++++++++++- 6 files changed, 43 insertions(+), 34 deletions(-) delete mode 100644 poollet/common/defaults/defaults.go diff --git a/poollet/bucketpoollet/cmd/bucketpoollet/app/app.go b/poollet/bucketpoollet/cmd/bucketpoollet/app/app.go index 1007bc816..d23aec753 100644 --- a/poollet/bucketpoollet/cmd/bucketpoollet/app/app.go +++ b/poollet/bucketpoollet/cmd/bucketpoollet/app/app.go @@ -22,7 +22,6 @@ import ( "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/bem" bucketpoolletconfig "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/client/config" "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/controllers" - "github.com/ironcore-dev/ironcore/poollet/common/defaults" "github.com/ironcore-dev/ironcore/poollet/irievent" "github.com/ironcore-dev/ironcore/utils/client/config" @@ -67,8 +66,6 @@ type Options struct { WatchFilterValue string - QPS float32 - Burst int MaxConcurrentReconciles int } @@ -95,8 +92,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.WatchFilterValue, "watch-filter", "", "Value to filter for while watching.") - fs.Float32Var(&o.QPS, "qps", defaults.QPS, "Kubernetes client qps.") - fs.IntVar(&o.Burst, "burst", defaults.Burst, "Kubernetes client burst.") fs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", 1, "Maximum number of concurrent reconciles.") } @@ -160,8 +155,6 @@ func Run(ctx context.Context, opts Options) error { } setupLog.Info("IRI Client configuration", "ChannelCapacity", opts.ChannelCapacity, "RelistPeriod", opts.RelistPeriod, "RelistThreshold", opts.RelistThreshold) - cfg.QPS = opts.QPS - cfg.Burst = opts.Burst setupLog.Info("Kubernetes Client configuration", "QPS", cfg.QPS, "Burst", cfg.Burst) leaderElectionCfg, err := configutils.GetConfig( diff --git a/poollet/common/defaults/defaults.go b/poollet/common/defaults/defaults.go deleted file mode 100644 index bf1035182..000000000 --- a/poollet/common/defaults/defaults.go +++ /dev/null @@ -1,9 +0,0 @@ -// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors -// SPDX-License-Identifier: Apache-2.0 - -package defaults - -const ( - QPS float32 = 20.0 - Burst int = 30 -) diff --git a/poollet/machinepoollet/cmd/machinepoollet/app/app.go b/poollet/machinepoollet/cmd/machinepoollet/app/app.go index 035e71a88..3dacf1ac3 100644 --- a/poollet/machinepoollet/cmd/machinepoollet/app/app.go +++ b/poollet/machinepoollet/cmd/machinepoollet/app/app.go @@ -21,7 +21,6 @@ import ( computeclient "github.com/ironcore-dev/ironcore/internal/client/compute" iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1" iriremotemachine "github.com/ironcore-dev/ironcore/iri/remote/machine" - "github.com/ironcore-dev/ironcore/poollet/common/defaults" "github.com/ironcore-dev/ironcore/poollet/irievent" "github.com/ironcore-dev/ironcore/poollet/machinepoollet/addresses" machinepoolletclient "github.com/ironcore-dev/ironcore/poollet/machinepoollet/client" @@ -83,8 +82,6 @@ type Options struct { WatchFilterValue string - QPS float32 - Burst int MaxConcurrentReconciles int } @@ -117,8 +114,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.WatchFilterValue, "watch-filter", "", "Value to filter for while watching.") - fs.Float32Var(&o.QPS, "qps", defaults.QPS, "Kubernetes client qps.") - fs.IntVar(&o.Burst, "burst", defaults.Burst, "Kubernetes client burst.") fs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", 1, "Maximum number of concurrent reconciles.") } @@ -216,8 +211,6 @@ func Run(ctx context.Context, opts Options) error { } setupLog.Info("IRI Client configuration", "ChannelCapacity", opts.ChannelCapacity, "RelistPeriod", opts.RelistPeriod, "RelistThreshold", opts.RelistThreshold) - cfg.QPS = opts.QPS - cfg.Burst = opts.Burst setupLog.Info("Kubernetes Client configuration", "QPS", cfg.QPS, "Burst", cfg.Burst) leaderElectionCfg, err := configutils.GetConfig( diff --git a/poollet/volumepoollet/cmd/volumepoollet/app/app.go b/poollet/volumepoollet/cmd/volumepoollet/app/app.go index 39825e519..510c6caea 100644 --- a/poollet/volumepoollet/cmd/volumepoollet/app/app.go +++ b/poollet/volumepoollet/cmd/volumepoollet/app/app.go @@ -19,7 +19,6 @@ import ( storageclient "github.com/ironcore-dev/ironcore/internal/client/storage" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" iriremotevolume "github.com/ironcore-dev/ironcore/iri/remote/volume" - "github.com/ironcore-dev/ironcore/poollet/common/defaults" "github.com/ironcore-dev/ironcore/poollet/irievent" volumepoolletconfig "github.com/ironcore-dev/ironcore/poollet/volumepoollet/client/config" "github.com/ironcore-dev/ironcore/poollet/volumepoollet/controllers" @@ -68,8 +67,6 @@ type Options struct { WatchFilterValue string - QPS float32 - Burst int MaxConcurrentReconciles int } @@ -96,8 +93,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.WatchFilterValue, "watch-filter", "", "Value to filter for while watching.") - fs.Float32Var(&o.QPS, "qps", defaults.QPS, "Kubernetes client qps.") - fs.IntVar(&o.Burst, "burst", defaults.Burst, "Kubernetes client burst.") fs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", 1, "Maximum number of concurrent reconciles.") } @@ -160,8 +155,6 @@ func Run(ctx context.Context, opts Options) error { } setupLog.Info("IRI Client configuration", "ChannelCapacity", opts.ChannelCapacity, "RelistPeriod", opts.RelistPeriod, "RelistThreshold", opts.RelistThreshold) - cfg.QPS = opts.QPS - cfg.Burst = opts.Burst setupLog.Info("Kubernetes Client configuration", "QPS", cfg.QPS, "Burst", cfg.Burst) leaderElectionCfg, err := configutils.GetConfig( diff --git a/utils/client/config/config.go b/utils/client/config/config.go index 2c49e2853..a0731fd29 100644 --- a/utils/client/config/config.go +++ b/utils/client/config/config.go @@ -14,7 +14,9 @@ import ( "time" "github.com/go-logr/logr" + utilrest "github.com/ironcore-dev/ironcore/utils/rest" + certificatesv1 "k8s.io/api/certificates/v1" corev1 "k8s.io/api/core/v1" utilnet "k8s.io/apimachinery/pkg/util/net" @@ -44,12 +46,16 @@ const ( // EgressSelectorConfigFlagName is the name of the egress-selector-config flag. EgressSelectorConfigFlagName = "egress-selector-config" -) -var ( - log = ctrl.Log.WithName("client").WithName("config") + // QPS is the default value for allowed queries per second for a client. + QPS float32 = 20.0 + + // Burst is the default value for allowed burst rate for a client. + Burst int = 30 ) +var log = ctrl.Log.WithName("client").WithName("config") + // EgressSelectionName is the name of the egress configuration to use. type EgressSelectionName string @@ -273,6 +279,8 @@ func (g *Getter) getConfig(ctx context.Context, o *GetConfigOptions) (*rest.Conf } cfg.Dial = dialFunc + cfg.QPS = o.QPS + cfg.Burst = o.Burst return cfg, nil, nil } diff --git a/utils/client/config/options.go b/utils/client/config/options.go index d593ee33a..3aeb12297 100644 --- a/utils/client/config/options.go +++ b/utils/client/config/options.go @@ -6,8 +6,9 @@ package config import ( "fmt" - "github.com/ironcore-dev/ironcore/utils/generic" "github.com/spf13/pflag" + + "github.com/ironcore-dev/ironcore/utils/generic" ) // GetConfigOptions are options to supply for a GetConfig call. @@ -38,6 +39,12 @@ type GetConfigOptions struct { // EgressSelectorConfig is the path to an egress selector config to load. EgressSelectorConfig string + + // QPS specifies the queries per second allowed for the client. + QPS float32 + + // Burst specified the burst rate allowed for the client. + Burst int } // BindFlagOptions are options for GetConfigOptions.BindFlags. @@ -80,6 +87,8 @@ func (o *GetConfigOptions) BindFlags(fs *pflag.FlagSet, opts ...func(*BindFlagOp fs.StringVar(&o.BootstrapKubeconfig, bo.NameFunc(BootstrapKubeconfigFlagName), "", "Path to a bootstrap kubeconfig.") fs.BoolVar(&o.RotateCertificates, bo.NameFunc(RotateCertificatesFlagName), false, "Whether to use automatic certificate / config rotation.") fs.StringVar(&o.EgressSelectorConfig, bo.NameFunc(EgressSelectorConfigFlagName), "", "Path pointing to an egress selector config to use.") + fs.Float32Var(&o.QPS, "qps", QPS, "Kubernetes client qps.") + fs.IntVar(&o.Burst, "burst", Burst, "Kubernetes client burst.") } // ApplyToGetConfig implements GetConfigOption. @@ -105,6 +114,12 @@ func (o *GetConfigOptions) ApplyToGetConfig(o2 *GetConfigOptions) { if o.EgressSelectorConfig != "" { o2.EgressSelectorConfig = o.EgressSelectorConfig } + if o.QPS != 0 { + o2.QPS = o.QPS + } + if o.Burst != 0 { + o2.Burst = o.Burst + } } // ApplyOptions applies all GetConfigOption tro this GetConfigOptions. @@ -146,3 +161,19 @@ func (w WithRotate) ApplyToGetConfig(o *GetConfigOptions) { // RotateCertificates enables certificate rotation. var RotateCertificates = WithRotate(true) + +// WithQPS sets GetConfigOptions.QPS to the specified value. +type WithQPS float32 + +// ApplyToGetConfig implements GetConfigOption. +func (c WithQPS) ApplyToGetConfig(o *GetConfigOptions) { + o.QPS = float32(c) +} + +// WithBurst sets GetConfigOptions.Burst to the specified value. +type WithBurst int + +// ApplyToGetConfig implements GetConfigOption. +func (c WithBurst) ApplyToGetConfig(o *GetConfigOptions) { + o.Burst = int(c) +}