Skip to content

Commit

Permalink
add qps/burst flag for k8s client,and provide method to hide flags
Browse files Browse the repository at this point in the history
  • Loading branch information
whitebear009 committed Dec 7, 2022
1 parent 41ec178 commit 17125fb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pkg/cmd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ type AdapterBase struct {
// DiscoveryInterval specifies the interval at which to recheck discovery
// information for the discovery RESTMapper. It's set from a flag.
DiscoveryInterval time.Duration
// ClientQPS specifies the maximum QPS for the client-side throttle. It's set from a flag.
ClientQPS float32
// ClientBurst specifies the maximum QPS burst for client-side throttle. It's set from a flag.
ClientBurst int

// MarkQPSFlagHidden specifies whether to hide the client-qps and client-burst flags.
// If you want to use other flags, you can hide them.
MarkQPSFlagHidden bool

// FlagSet is the flagset to add flags to.
// It defaults to the normal CommandLine flags
Expand Down Expand Up @@ -110,7 +118,15 @@ func (b *AdapterBase) InstallFlags() {
"kubeconfig file pointing at the 'core' kubernetes server with enough rights to list "+
"any described objects")
b.FlagSet.DurationVar(&b.DiscoveryInterval, "discovery-interval", b.DiscoveryInterval,
"interval at which to refresh API discovery information")
"Interval at which to refresh API discovery information")
b.FlagSet.Float32Var(&b.ClientQPS, "client-qps", rest.DefaultQPS, "Maximum QPS for client-side throttle")
b.FlagSet.IntVar(&b.ClientBurst, "client-burst", rest.DefaultBurst, "Maximum QPS burst for client-side throttle")

if b.MarkQPSFlagHidden {
// ignore the error if flags does not exist
_ = b.FlagSet.MarkHidden("client-qps")
_ = b.FlagSet.MarkHidden("client-burst")
}
})
}

Expand Down Expand Up @@ -153,6 +169,13 @@ func (b *AdapterBase) ClientConfig() (*rest.Config, error) {
}
b.clientConfig = clientConfig
}

if b.ClientQPS > 0 {
b.clientConfig.QPS = b.ClientQPS
}
if b.ClientBurst > 0 {
b.clientConfig.Burst = b.ClientBurst
}
return b.clientConfig, nil
}

Expand Down

0 comments on commit 17125fb

Please sign in to comment.