Skip to content

Commit

Permalink
change poollet client specific qps and burst opts implementation to c…
Browse files Browse the repository at this point in the history
…ommon options pattern
  • Loading branch information
balpert89 committed Nov 26, 2024
1 parent afcae77 commit 8895d51
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
7 changes: 0 additions & 7 deletions poollet/bucketpoollet/cmd/bucketpoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -67,8 +66,6 @@ type Options struct {

WatchFilterValue string

QPS float32
Burst int
MaxConcurrentReconciles int
}

Expand All @@ -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.")
}

Expand Down Expand Up @@ -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(
Expand Down
9 changes: 0 additions & 9 deletions poollet/common/defaults/defaults.go

This file was deleted.

7 changes: 0 additions & 7 deletions poollet/machinepoollet/cmd/machinepoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,8 +82,6 @@ type Options struct {

WatchFilterValue string

QPS float32
Burst int
MaxConcurrentReconciles int
}

Expand Down Expand Up @@ -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.")
}

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions poollet/volumepoollet/cmd/volumepoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -68,8 +67,6 @@ type Options struct {

WatchFilterValue string

QPS float32
Burst int
MaxConcurrentReconciles int
}

Expand All @@ -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.")
}

Expand Down Expand Up @@ -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(
Expand Down
14 changes: 11 additions & 3 deletions utils/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

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

Expand Down
33 changes: 32 additions & 1 deletion utils/client/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}

0 comments on commit 8895d51

Please sign in to comment.