Skip to content

Commit

Permalink
update default qps for webhook (open-cluster-management-io#141)
Browse files Browse the repository at this point in the history
Signed-off-by: ldpliu <daliu@redhat.com>
  • Loading branch information
ldpliu authored Jun 20, 2022
1 parent 10b572b commit 6f53412
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions pkg/cmd/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,78 @@ import (

admissionserver "github.com/openshift/generic-admission-server/pkg/cmd/server"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
genericapiserver "k8s.io/apiserver/pkg/server"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"open-cluster-management.io/work/pkg/webhook"
)

func NewAdmissionHook() *cobra.Command {
o := admissionserver.NewAdmissionServerOptions(os.Stdout, os.Stderr, &webhook.ManifestWorkAdmissionHook{})

ops := NewOptions()
cmd := &cobra.Command{
Use: "webhook",
Short: "Start Managed Cluster Admission Server",
RunE: func(c *cobra.Command, args []string) error {
stopCh := genericapiserver.SetupSignalHandler()

if err := o.Complete(); err != nil {
if err := ops.ServerOptions.Complete(); err != nil {
return err
}
if err := o.Validate(args); err != nil {
if err := ops.ServerOptions.Validate(args); err != nil {
return err
}
if err := o.RunAdmissionServer(stopCh); err != nil {
if err := ops.RunAdmissionServer(ops.ServerOptions, stopCh); err != nil {
return err
}
return nil
},
}

flags := cmd.Flags()
ops.AddFlags(flags)
return cmd
}

// Config contains the server (the webhook) cert and key.
type Options struct {
QPS float32
Burst int
ServerOptions *admissionserver.AdmissionServerOptions
}

// NewOptions constructs a new set of default options for webhook.
func NewOptions() *Options {
return &Options{
QPS: 100.0,
Burst: 200,
ServerOptions: admissionserver.NewAdmissionServerOptions(os.Stdout, os.Stderr, &webhook.ManifestWorkAdmissionHook{}),
}
}

func (c *Options) AddFlags(fs *pflag.FlagSet) {
fs.Float32Var(&c.QPS, "max-qps", c.QPS,
"Maximum QPS to the hub server from this webhook.")
fs.IntVar(&c.Burst, "max-burst", c.Burst,
"Maximum burst for throttle.")

featureGate := utilfeature.DefaultMutableFeatureGate
featureGate.AddFlag(flags)
o.RecommendedOptions.FeatureGate = featureGate
featureGate.AddFlag(fs)

o.RecommendedOptions.AddFlags(cmd.Flags())
c.ServerOptions.RecommendedOptions.FeatureGate = featureGate
c.ServerOptions.RecommendedOptions.AddFlags(fs)
}

return cmd
// change the default QPS and Butst, so rewrite this func
func (c *Options) RunAdmissionServer(o *admissionserver.AdmissionServerOptions, stopCh <-chan struct{}) error {
config, err := o.Config()
if err != nil {
return err
}
config.RestConfig.QPS = c.QPS
config.RestConfig.Burst = c.Burst
server, err := config.Complete().New()
if err != nil {
return err
}
return server.GenericAPIServer.PrepareRun().Run(stopCh)
}

0 comments on commit 6f53412

Please sign in to comment.