Skip to content

Commit 01af879

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

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

pkg/cmd/builder.go

+23-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 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,14 @@ 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+
b.FlagSet.MarkHidden("client-qps")
127+
b.FlagSet.MarkHidden("client-burst")
128+
}
114129
})
115130
}
116131

@@ -153,6 +168,13 @@ func (b *AdapterBase) ClientConfig() (*rest.Config, error) {
153168
}
154169
b.clientConfig = clientConfig
155170
}
171+
172+
if b.ClientQPS > 0 {
173+
b.clientConfig.QPS = b.ClientQPS
174+
}
175+
if b.ClientBurst > 0 {
176+
b.clientConfig.Burst = b.ClientBurst
177+
}
156178
return b.clientConfig, nil
157179
}
158180

0 commit comments

Comments
 (0)