diff --git a/cmd/admission/app/options/options.go b/cmd/admission/app/options/options.go index 5ca24216a8..98dd1bd8f0 100644 --- a/cmd/admission/app/options/options.go +++ b/cmd/admission/app/options/options.go @@ -17,9 +17,10 @@ limitations under the License. package options import ( - "flag" "fmt" + "github.com/spf13/pflag" + "k8s.io/api/admissionregistration/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -57,27 +58,27 @@ func NewConfig() *Config { } // AddFlags add flags -func (c *Config) AddFlags() { - flag.StringVar(&c.Master, "master", c.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)") - flag.StringVar(&c.Kubeconfig, "kubeconfig", c.Kubeconfig, "Path to kubeconfig file with authorization and master location information.") - flag.StringVar(&c.CertFile, "tls-cert-file", c.CertFile, ""+ +func (c *Config) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&c.Master, "master", c.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)") + fs.StringVar(&c.Kubeconfig, "kubeconfig", c.Kubeconfig, "Path to kubeconfig file with authorization and master location information.") + fs.StringVar(&c.CertFile, "tls-cert-file", c.CertFile, ""+ "File containing the default x509 Certificate for HTTPS. (CA cert, if any, concatenated "+ "after server cert).") - flag.StringVar(&c.KeyFile, "tls-private-key-file", c.KeyFile, "File containing the default x509 private key matching --tls-cert-file.") - flag.StringVar(&c.CaCertFile, "ca-cert-file", c.CaCertFile, "File containing the x509 Certificate for HTTPS.") - flag.IntVar(&c.Port, "port", 443, "the port used by admission-controller-server.") - flag.StringVar(&c.MutateWebhookConfigName, "mutate-webhook-config-name", "", + fs.StringVar(&c.KeyFile, "tls-private-key-file", c.KeyFile, "File containing the default x509 private key matching --tls-cert-file.") + fs.StringVar(&c.CaCertFile, "ca-cert-file", c.CaCertFile, "File containing the x509 Certificate for HTTPS.") + fs.IntVar(&c.Port, "port", 443, "the port used by admission-controller-server.") + fs.StringVar(&c.MutateWebhookConfigName, "mutate-webhook-config-name", "", "Name of the mutatingwebhookconfiguration resource in Kubernetes [Deprecated]: it will be generated when not specified.") - flag.StringVar(&c.MutateWebhookName, "mutate-webhook-name", "", + fs.StringVar(&c.MutateWebhookName, "mutate-webhook-name", "", "Name of the webhook entry in the webhook config. [Deprecated]: it will be generated when not specified") - flag.StringVar(&c.ValidateWebhookConfigName, "validate-webhook-config-name", "", + fs.StringVar(&c.ValidateWebhookConfigName, "validate-webhook-config-name", "", "Name of the mutatingwebhookconfiguration resource in Kubernetes. [Deprecated]: it will be generated when not specified") - flag.StringVar(&c.ValidateWebhookName, "validate-webhook-name", "", + fs.StringVar(&c.ValidateWebhookName, "validate-webhook-name", "", "Name of the webhook entry in the webhook config. [Deprecated]: it will be generated when not specified") - flag.BoolVar(&c.PrintVersion, "version", false, "Show version and quit") - flag.StringVar(&c.AdmissionServiceNamespace, "webhook-namespace", "default", "The namespace of this webhook") - flag.StringVar(&c.AdmissionServiceName, "webhook-service-name", "admission-service", "The name of this admission service") - flag.StringVar(&c.SchedulerName, "scheduler-name", defaultSchedulerName, "Volcano will handle pods whose .spec.SchedulerName is same as scheduler-name") + fs.BoolVar(&c.PrintVersion, "version", false, "Show version and quit") + fs.StringVar(&c.AdmissionServiceNamespace, "webhook-namespace", "default", "The namespace of this webhook") + fs.StringVar(&c.AdmissionServiceName, "webhook-service-name", "admission-service", "The name of this admission service") + fs.StringVar(&c.SchedulerName, "scheduler-name", defaultSchedulerName, "Volcano will handle pods whose .spec.SchedulerName is same as scheduler-name") } const ( diff --git a/cmd/admission/main.go b/cmd/admission/main.go index 60e5e5313c..37bc9e2ff4 100644 --- a/cmd/admission/main.go +++ b/cmd/admission/main.go @@ -16,14 +16,19 @@ limitations under the License. package main import ( - "flag" "io/ioutil" "net/http" "os" "os/signal" + "runtime" "strconv" "syscall" + "time" + "github.com/spf13/pflag" + + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apiserver/pkg/util/flag" "k8s.io/client-go/tools/clientcmd" "k8s.io/klog" @@ -41,15 +46,24 @@ func serveMutateJobs(w http.ResponseWriter, r *http.Request) { admission.Serve(w, r, admission.MutateJobs) } +var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes") + func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) + klog.InitFlags(nil) + config := options.NewConfig() - config.AddFlags() - flag.Parse() + config.AddFlags(pflag.CommandLine) + + flag.InitFlags() if config.PrintVersion { version.PrintVersionAndExit() } + go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop) + defer klog.Flush() + http.HandleFunc(admission.AdmitJobPath, serveJobs) http.HandleFunc(admission.MutateJobPath, serveMutateJobs) diff --git a/cmd/controllers/main.go b/cmd/controllers/main.go index 44623c6800..20df8642e3 100644 --- a/cmd/controllers/main.go +++ b/cmd/controllers/main.go @@ -18,6 +18,7 @@ package main import ( "fmt" "os" + "runtime" "time" "github.com/spf13/pflag" @@ -34,11 +35,13 @@ import ( var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes") func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) + klog.InitFlags(nil) + s := options.NewServerOption() s.AddFlags(pflag.CommandLine) flag.InitFlags() - klog.InitFlags(nil) if s.PrintVersion { version.PrintVersionAndExit()