Skip to content

Commit 994219c

Browse files
committed
add qps/burst flag for k8s client, and provide method to hide flags
1 parent 41ec178 commit 994219c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pkg/cmd/builder.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ type AdapterBase struct {
6767
// DiscoveryInterval specifies the interval at which to recheck discovery
6868
// information for the discovery RESTMapper. It's set from a flag.
6969
DiscoveryInterval time.Duration
70+
// ClientQPS specifies the maximum QPS for the client-side throttle. It's set from a flag.
71+
ClientQPS float32
72+
// ClientBurst specifies the maximum QPS burst for client-side throttle. It's set from a flag.
73+
ClientBurst int
74+
75+
// MarkQPSFlagHidden specifies whether to hide the client-qps and client-burst flags.
76+
// If you want to use other flags, you can set to true to hide them.
77+
MarkQPSFlagHidden bool
7078

7179
// FlagSet is the flagset to add flags to.
7280
// It defaults to the normal CommandLine flags
@@ -110,7 +118,15 @@ func (b *AdapterBase) InstallFlags() {
110118
"kubeconfig file pointing at the 'core' kubernetes server with enough rights to list "+
111119
"any described objects")
112120
b.FlagSet.DurationVar(&b.DiscoveryInterval, "discovery-interval", b.DiscoveryInterval,
113-
"interval at which to refresh API discovery information")
121+
"Interval at which to refresh API discovery information")
122+
b.FlagSet.Float32Var(&b.ClientQPS, "client-qps", rest.DefaultQPS, "Maximum QPS for client-side throttle")
123+
b.FlagSet.IntVar(&b.ClientBurst, "client-burst", rest.DefaultBurst, "Maximum QPS burst for client-side throttle")
124+
125+
if b.MarkQPSFlagHidden {
126+
// ignore the error if flags does not exist
127+
_ = b.FlagSet.MarkHidden("client-qps")
128+
_ = b.FlagSet.MarkHidden("client-burst")
129+
}
114130
})
115131
}
116132

@@ -153,6 +169,13 @@ func (b *AdapterBase) ClientConfig() (*rest.Config, error) {
153169
}
154170
b.clientConfig = clientConfig
155171
}
172+
173+
if b.ClientQPS > 0 {
174+
b.clientConfig.QPS = b.ClientQPS
175+
}
176+
if b.ClientBurst > 0 {
177+
b.clientConfig.Burst = b.ClientBurst
178+
}
156179
return b.clientConfig, nil
157180
}
158181

0 commit comments

Comments
 (0)