Skip to content

Commit 7e59e4e

Browse files
authored
Add --qps and --burst flags to contorl client-side throttling (#363)
* Add --qps and --burst flags to contorl client-side throttling Signed-off-by: Abhishek Pareek <makeittotop@users.noreply.github.com> * switch burst to default in case qps is gt than 0 to fix panic Signed-off-by: Abhishek Pareek <makeittotop@users.noreply.github.com> --------- Signed-off-by: Abhishek Pareek <makeittotop@users.noreply.github.com> Co-authored-by: Abhishek Pareek <makeittotop@users.noreply.github.com>
1 parent 72148a9 commit 7e59e4e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Supported Kubernetes resources are `pod`, `replicationcontroller`, `service`, `d
7979
flag | default | purpose
8080
-----------------------------|-------------------------------|---------
8181
`--all-namespaces`, `-A` | `false` | If present, tail across all namespaces. A specific namespace is ignored even if specified with --namespace.
82+
`--burst` | `0` | Maximum burst for throttle to the Kubernetes API server. Defaults to 0 (use client-go default). Ignored when --qps=-1.
8283
`--color` | `auto` | Force set color output. 'auto': colorize if tty attached, 'always': always colorize, 'never': never colorize.
8384
`--completion` | | Output stern command-line completion code for the specified shell. Can be 'bash', 'zsh' or 'fish'.
8485
`--condition` | | The condition to filter on: [condition-name[=condition-value]. The default condition-value is true. Match is case-insensitive. Currently only supported with --tail=0 or --no-follow.
@@ -105,6 +106,7 @@ Supported Kubernetes resources are `pod`, `replicationcontroller`, `service`, `d
105106
`--output`, `-o` | `default` | Specify predefined template. Currently support: [default, raw, json, extjson, ppextjson]
106107
`--pod-colors` | | Specifies the colors used to highlight pod names. Provide colors as a comma-separated list using SGR (Select Graphic Rendition) sequences, e.g., "91,92,93,94,95,96".
107108
`--prompt`, `-p` | `false` | Toggle interactive prompt for selecting 'app.kubernetes.io/instance' label values.
109+
`--qps` | `0` | Maximum QPS to the Kubernetes API server. Defaults to 0 (use client-go default). Use -1 to disable client-side throttling.
108110
`--selector`, `-l` | | Selector (label query) to filter on. If present, default to ".*" for the pod-query.
109111
`--show-hidden-options` | `false` | Print a list of hidden options.
110112
`--since`, `-s` | `48h0m0s` | Return logs newer than a relative duration like 5s, 2m, or 3h.

cmd/cmd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"k8s.io/apimachinery/pkg/labels"
3939
"k8s.io/cli-runtime/pkg/genericclioptions"
4040
"k8s.io/client-go/kubernetes"
41+
"k8s.io/client-go/rest"
4142
"k8s.io/client-go/tools/clientcmd"
4243
"k8s.io/klog/v2"
4344

@@ -83,6 +84,8 @@ type options struct {
8384
verbosity int
8485
onlyLogLines bool
8586
maxLogRequests int
87+
qps float32
88+
burst int
8689
node string
8790
configFilePath string
8891
showHiddenOptions bool
@@ -145,6 +148,15 @@ func (o *options) Complete(args []string) error {
145148
return err
146149
}
147150

151+
if o.qps != 0 {
152+
restConfig.QPS = o.qps
153+
}
154+
if o.burst > 0 {
155+
restConfig.Burst = o.burst
156+
} else if o.qps > 0 {
157+
restConfig.Burst = rest.DefaultBurst
158+
}
159+
148160
o.client = kubernetes.NewForConfigOrDie(restConfig)
149161

150162
if len(o.namespaces) == 0 {
@@ -448,6 +460,8 @@ func (o *options) AddFlags(fs *pflag.FlagSet) {
448460
fs.StringSliceVarP(&o.namespaces, "namespace", "n", o.namespaces, "Kubernetes namespace to use. Default to namespace configured in kubernetes context. To specify multiple namespaces, repeat this or set comma-separated value.")
449461
fs.StringVar(&o.node, "node", o.node, "Node name to filter on.")
450462
fs.IntVar(&o.maxLogRequests, "max-log-requests", o.maxLogRequests, "Maximum number of concurrent logs to request. Defaults to 50, but 5 when specifying --no-follow")
463+
fs.Float32Var(&o.qps, "qps", o.qps, "Maximum QPS to the Kubernetes API server. Defaults to 0 (use client-go default). Use -1 to disable client-side throttling.")
464+
fs.IntVar(&o.burst, "burst", o.burst, "Maximum burst for throttle to the Kubernetes API server. Defaults to 0 (use client-go default). Ignored when --qps=-1.")
451465
fs.StringVarP(&o.output, "output", "o", o.output, "Specify predefined template. Currently support: [default, raw, json, extjson, ppextjson]")
452466
fs.BoolVarP(&o.prompt, "prompt", "p", o.prompt, "Toggle interactive prompt for selecting 'app.kubernetes.io/instance' label values.")
453467
fs.StringVarP(&o.selector, "selector", "l", o.selector, "Selector (label query) to filter on. If present, default to \".*\" for the pod-query.")

0 commit comments

Comments
 (0)