mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
fix: make flag default values configurable (#6883)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
f7f3bc79d2
commit
c30934add2
2 changed files with 44 additions and 8 deletions
|
@ -70,10 +70,10 @@ func initMetricsFlags() {
|
|||
flag.BoolVar(&disableMetricsExport, "disableMetrics", false, "Set this flag to 'true' to disable metrics.")
|
||||
}
|
||||
|
||||
func initKubeconfigFlags() {
|
||||
func initKubeconfigFlags(qps float64, burst int) {
|
||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
|
||||
flag.Float64Var(&clientRateLimitQPS, "clientRateLimitQPS", 20, "Configure the maximum QPS to the Kubernetes API server from Kyverno. Uses the client default if zero.")
|
||||
flag.IntVar(&clientRateLimitBurst, "clientRateLimitBurst", 50, "Configure the maximum burst for throttle. Uses the client default if zero.")
|
||||
flag.Float64Var(&clientRateLimitQPS, "clientRateLimitQPS", qps, "Configure the maximum QPS to the Kubernetes API server from Kyverno. Uses the client default if zero.")
|
||||
flag.IntVar(&clientRateLimitBurst, "clientRateLimitBurst", burst, "Configure the maximum burst for throttle. Uses the client default if zero.")
|
||||
}
|
||||
|
||||
func initPolicyExceptionsFlags() {
|
||||
|
@ -98,7 +98,39 @@ func initLeaderElectionFlags() {
|
|||
flag.DurationVar(&leaderElectionRetryPeriod, "leaderElectionRetryPeriod", leaderelection.DefaultRetryPeriod, "Configure leader election retry period.")
|
||||
}
|
||||
|
||||
func InitFlags(config Configuration) {
|
||||
type options struct {
|
||||
clientRateLimitQPS float64
|
||||
clientRateLimitBurst int
|
||||
}
|
||||
|
||||
func newOptions() options {
|
||||
return options{
|
||||
clientRateLimitQPS: 20,
|
||||
clientRateLimitBurst: 50,
|
||||
}
|
||||
}
|
||||
|
||||
type Option = func(*options)
|
||||
|
||||
func WithDefaultQps(qps float64) Option {
|
||||
return func(o *options) {
|
||||
o.clientRateLimitQPS = qps
|
||||
}
|
||||
}
|
||||
|
||||
func WithDefaultBurst(burst int) Option {
|
||||
return func(o *options) {
|
||||
o.clientRateLimitBurst = burst
|
||||
}
|
||||
}
|
||||
|
||||
func initFlags(config Configuration, opts ...Option) {
|
||||
options := newOptions()
|
||||
for _, o := range opts {
|
||||
if o != nil {
|
||||
o(&options)
|
||||
}
|
||||
}
|
||||
// logging
|
||||
initLoggingFlags()
|
||||
// profiling
|
||||
|
@ -115,7 +147,7 @@ func InitFlags(config Configuration) {
|
|||
}
|
||||
// kubeconfig
|
||||
if config.UsesKubeconfig() {
|
||||
initKubeconfigFlags()
|
||||
initKubeconfigFlags(options.clientRateLimitQPS, options.clientRateLimitBurst)
|
||||
}
|
||||
// policy exceptions
|
||||
if config.UsesPolicyExceptions() {
|
||||
|
@ -144,8 +176,8 @@ func InitFlags(config Configuration) {
|
|||
}
|
||||
}
|
||||
|
||||
func ParseFlags(config Configuration) {
|
||||
InitFlags(config)
|
||||
func ParseFlags(config Configuration, opts ...Option) {
|
||||
initFlags(config, opts...)
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,11 @@ func main() {
|
|||
internal.WithFlagSets(flagset),
|
||||
)
|
||||
// parse flags
|
||||
internal.ParseFlags(appConfig)
|
||||
internal.ParseFlags(
|
||||
appConfig,
|
||||
internal.WithDefaultQps(300),
|
||||
internal.WithDefaultBurst(300),
|
||||
)
|
||||
// setup
|
||||
ctx, setup, sdown := internal.Setup(appConfig, "kyverno-reports-controller", skipResourceFilters)
|
||||
defer sdown()
|
||||
|
|
Loading…
Reference in a new issue