Skip to content

Commit

Permalink
update flag parse in webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Mar 1, 2022
1 parent a3975fe commit 4f987b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions cmd/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
ovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
ovnwebhook "github.com/kubeovn/kube-ovn/pkg/webhook"
"github.com/kubeovn/kube-ovn/versions"
"github.com/spf13/pflag"
)

const (
Expand All @@ -40,9 +41,25 @@ func CmdMain() {
var port int
klog.Infof(versions.String())

flag.IntVar(&port, "port", 8443, "The port webhook listen on.")
klog.InitFlags(nil)
flag.Parse()
port = *pflag.Int("port", 8443, "The port webhook listen on.")

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)

// Sync the glog and klog flags.
pflag.CommandLine.VisitAll(func(f1 *pflag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
if err := f2.Value.Set(value); err != nil {
klog.Fatalf("failed to set flag, %v", err)
}
}
})

pflag.CommandLine.AddGoFlagSet(klogFlags)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

// set logger for controller-runtime framework
ctrl.SetLogger(klogr.New())
Expand Down
2 changes: 1 addition & 1 deletion yamls/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-webhook
image: "kubeovn/kube-ovn:v1.9.0"
image: "kubeovn/kube-ovn:v1.10.0"
imagePullPolicy: IfNotPresent
command:
- /kube-ovn/kube-ovn-webhook
Expand Down

0 comments on commit 4f987b1

Please sign in to comment.