提交 85b722c7 编写于 作者: P Priya Modali

Setting klog default flag values.

上级 3703f69c
......@@ -17,7 +17,7 @@ limitations under the License.
package cmd
import (
"flag"
goflag "flag"
"fmt"
"os"
"path/filepath"
......@@ -76,16 +76,16 @@ func Execute() {
for _, c := range RootCmd.Commands() {
c.Short = translate.T(c.Short)
c.Long = translate.T(c.Long)
c.Flags().VisitAll(func(flag *pflag.Flag) {
flag.Usage = translate.T(flag.Usage)
c.Flags().VisitAll(func(f *pflag.Flag) {
f.Usage = translate.T(f.Usage)
})
c.SetUsageTemplate(usageTemplate())
}
RootCmd.Short = translate.T(RootCmd.Short)
RootCmd.Long = translate.T(RootCmd.Long)
RootCmd.Flags().VisitAll(func(flag *pflag.Flag) {
flag.Usage = translate.T(flag.Usage)
RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
f.Usage = translate.T(f.Usage)
})
if runtime.GOOS != "windows" {
......@@ -140,26 +140,6 @@ func usageTemplate() string {
}
func init() {
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
// Sync the glog and klog flags.
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
// we need to special case this flag because the default value in glog
// is incompatible in klog
if f1.Name == "log_backtrace_at" {
value = ""
}
if err := f2.Value.Set(value); err != nil {
klog.Warningf("Error reading flag value %s: %v", f1.Name, err)
}
}
})
translate.DetermineLocale()
RootCmd.PersistentFlags().StringP(config.ProfileName, "p", constants.DefaultClusterName, `The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.`)
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", "kubeadm", "The name of the cluster bootstrapper that will set up the Kubernetes cluster.")
......@@ -227,10 +207,17 @@ func init() {
RootCmd.AddCommand(completionCmd)
templates.ActsAsRootCommand(RootCmd, []string{"options"}, groups...)
pflag.CommandLine.AddGoFlagSet(klogFlags)
klog.InitFlags(nil)
goflag.Set("logtostderr", "false")
goflag.Set("alsologtostderr", "false")
goflag.Parse()
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
exit.Error(reason.InternalBindFlags, "Unable to bind flags", err)
}
translate.DetermineLocale()
cobra.OnInitialize(initConfig)
}
......
diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go
index 4654bfdd0..1757d10cc 100644
--- a/cmd/minikube/cmd/root.go
+++ b/cmd/minikube/cmd/root.go
@@ -17,7 +17,7 @@ limitations under the License.
package cmd
import (
- "flag"
+ goflag "flag"
"fmt"
"os"
"path/filepath"
@@ -76,16 +76,16 @@ func Execute() {
for _, c := range RootCmd.Commands() {
c.Short = translate.T(c.Short)
c.Long = translate.T(c.Long)
- c.Flags().VisitAll(func(flag *pflag.Flag) {
- flag.Usage = translate.T(flag.Usage)
+ c.Flags().VisitAll(func(f *pflag.Flag) {
+ f.Usage = translate.T(f.Usage)
})
c.SetUsageTemplate(usageTemplate())
}
RootCmd.Short = translate.T(RootCmd.Short)
RootCmd.Long = translate.T(RootCmd.Long)
- RootCmd.Flags().VisitAll(func(flag *pflag.Flag) {
- flag.Usage = translate.T(flag.Usage)
+ RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
+ f.Usage = translate.T(f.Usage)
})
if runtime.GOOS != "windows" {
@@ -138,23 +138,7 @@ func usageTemplate() string {
%s{{end}}
`, translate.T("Usage"), translate.T("Aliases"), translate.T("Examples"), translate.T("Available Commands"), translate.T("Flags"), translate.T("Global Flags"), translate.T("Additional help topics"), translate.T(`Use "{{.CommandPath}} [command] --help" for more information about a command.`))
}
-
func init() {
- klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
- klog.InitFlags(klogFlags)
-
- // Sync the glog and klog flags.
- flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
- f2 := klogFlags.Lookup(f1.Name)
- if f2 != nil {
- value := f1.Value.String()
- if err := f2.Value.Set(value); err != nil {
- klog.Warningf("Error reading flag value %s: %v", f1.Name, err)
- }
- }
- })
-
- translate.DetermineLocale()
RootCmd.PersistentFlags().StringP(config.ProfileName, "p", constants.DefaultClusterName, `The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.`)
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", "kubeadm", "The name of the cluster bootstrapper that will set up the Kubernetes cluster.")
@@ -222,10 +206,17 @@ func init() {
RootCmd.AddCommand(completionCmd)
templates.ActsAsRootCommand(RootCmd, []string{"options"}, groups...)
- pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
+ klog.InitFlags(nil)
+ goflag.Set("logtostderr", "false")
+ goflag.Set("alsologtostderr", "false")
+ goflag.Parse()
+
+ pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
exit.Error(reason.InternalBindFlags, "Unable to bind flags", err)
}
+
+ translate.DetermineLocale()
cobra.OnInitialize(initConfig)
}
diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go
index 4654bfdd0..1757d10cc 100644
--- a/cmd/minikube/cmd/root.go
+++ b/cmd/minikube/cmd/root.go
@@ -17,7 +17,7 @@ limitations under the License.
package cmd
import (
- "flag"
+ goflag "flag"
"fmt"
"os"
"path/filepath"
@@ -76,16 +76,16 @@ func Execute() {
for _, c := range RootCmd.Commands() {
c.Short = translate.T(c.Short)
c.Long = translate.T(c.Long)
- c.Flags().VisitAll(func(flag *pflag.Flag) {
- flag.Usage = translate.T(flag.Usage)
+ c.Flags().VisitAll(func(f *pflag.Flag) {
+ f.Usage = translate.T(f.Usage)
})
c.SetUsageTemplate(usageTemplate())
}
RootCmd.Short = translate.T(RootCmd.Short)
RootCmd.Long = translate.T(RootCmd.Long)
- RootCmd.Flags().VisitAll(func(flag *pflag.Flag) {
- flag.Usage = translate.T(flag.Usage)
+ RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
+ f.Usage = translate.T(f.Usage)
})
if runtime.GOOS != "windows" {
@@ -138,23 +138,7 @@ func usageTemplate() string {
%s{{end}}
`, translate.T("Usage"), translate.T("Aliases"), translate.T("Examples"), translate.T("Available Commands"), translate.T("Flags"), translate.T("Global Flags"), translate.T("Additional help topics"), translate.T(`Use "{{.CommandPath}} [command] --help" for more information about a command.`))
}
-
func init() {
- klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
- klog.InitFlags(klogFlags)
-
- // Sync the glog and klog flags.
- flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
- f2 := klogFlags.Lookup(f1.Name)
- if f2 != nil {
- value := f1.Value.String()
- if err := f2.Value.Set(value); err != nil {
- klog.Warningf("Error reading flag value %s: %v", f1.Name, err)
- }
- }
- })
-
- translate.DetermineLocale()
RootCmd.PersistentFlags().StringP(config.ProfileName, "p", constants.DefaultClusterName, `The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.`)
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", "kubeadm", "The name of the cluster bootstrapper that will set up the Kubernetes cluster.")
@@ -222,10 +206,17 @@ func init() {
RootCmd.AddCommand(completionCmd)
templates.ActsAsRootCommand(RootCmd, []string{"options"}, groups...)
- pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
+ klog.InitFlags(nil)
+ goflag.Set("logtostderr", "false")
+ goflag.Set("alsologtostderr", "false")
+ goflag.Parse()
+
+ pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
exit.Error(reason.InternalBindFlags, "Unable to bind flags", err)
}
+
+ translate.DetermineLocale()
cobra.OnInitialize(initConfig)
}
......@@ -17,7 +17,6 @@ limitations under the License.
package cluster
import (
"flag"
"fmt"
"github.com/docker/machine/libmachine"
......@@ -29,19 +28,13 @@ import (
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/reason"
)
// This init function is used to set the logtostderr variable to false so that INFO level log info does not clutter the CLI
// INFO lvl logging is displayed due to the Kubernetes api calling flag.Set("logtostderr", "true") in its init()
// see: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/util/logs/logs.go#L32-L34
func init() {
if err := flag.Set("logtostderr", "false"); err != nil {
exit.Error(reason.InternalFlagSet, "unable to set logtostderr", err)
}
// Setting the default client to native gives much better performance.
ssh.SetDefaultClient(ssh.Native)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册