Skip to content

Commit

Permalink
Merge pull request #83 from zqzten/kube-api-qps-burst
Browse files Browse the repository at this point in the history
Introduce kube api qps & burst flags
  • Loading branch information
dayko2019 authored Dec 14, 2023
2 parents f51a642 + 61c2d9f commit 57fe3e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ import (
//+kubebuilder:scaffold:imports
)

const (
defaultQPS = float64(20)
defaultBurst = 30
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand Down Expand Up @@ -110,6 +115,8 @@ func main() {
metricsAddr string
probeAddr string
enableLeaderElection bool
kubeAPIQPS float64
kubeAPIBurst int
reconcileConcurrency int
objectLabelSelector string
objectFieldSelector string
Expand All @@ -131,6 +138,10 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Float64Var(&kubeAPIQPS, "kube-api-qps", defaultQPS, "QPS to use while talking with kubernetes apiserver."+
fmt.Sprintf("The number must be >= 0. If 0 will use defaultQPS: %f.", defaultQPS))
flag.IntVar(&kubeAPIBurst, "kube-api-burst", defaultBurst, "Burst to use while talking with kubernetes apiserver."+
fmt.Sprintf("The number must be >= 0. If 0 will use defaultBurst: %d.", defaultBurst))
flag.IntVar(&reconcileConcurrency, "reconcile-concurrency", 1, "The reconciliation concurrency of each controller.")
flag.StringVar(&objectLabelSelector, "object-label-selector", "", "The label selector to restrict controllers' list watch for objects.")
flag.StringVar(&objectFieldSelector, "object-field-selector", "", "The field selector to restrict controllers' list watch for objects.")
Expand Down Expand Up @@ -186,6 +197,14 @@ func main() {

cfg := ctrl.GetConfigOrDie()
rest.AddUserAgent(cfg, util.UserAgent)
if kubeAPIQPS <= 0 {
kubeAPIQPS = defaultQPS
}
cfg.QPS = float32(kubeAPIQPS)
if kubeAPIBurst <= 0 {
kubeAPIBurst = defaultBurst
}
cfg.Burst = kubeAPIBurst

var (
cacheObjectSelector = cache.ObjectSelector{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/metric/provider/prometheus/runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *MetricProvider) Start(ctx context.Context) error {
Steps: math.MaxInt32,
Cap: p.metricsRelistInterval,
}, func(ctx context.Context) (bool, error) {
metricsListerLog.V(2).Info("start to relist metrics")
metricsListerLog.V(1).Info("start to relist metrics")
if err := p.updateObjectSeries(ctx); err != nil {
metricsListerLog.Error(err, "failed to update object series")
return false, nil
Expand All @@ -58,6 +58,7 @@ func (p *MetricProvider) Start(ctx context.Context) error {
metricsListerLog.Error(err, "failed to update external series")
return false, nil
}
metricsListerLog.V(1).Info("metrics relisted successfully")
return true, nil
}); err != nil {
metricsListerLog.Error(err, "backoff stopped with unexpected error")
Expand Down

0 comments on commit 57fe3e3

Please sign in to comment.