From abca78dfdecf93bf7b7210288e43e31d09510b86 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Fri, 27 May 2016 15:17:58 -0700 Subject: [PATCH] Allow glog flags in localkube. --- cmd/localkube/cmd/root.go | 4 ++++ pkg/minikube/cluster/cluster.go | 1 + pkg/minikube/cluster/commands.go | 11 +++-------- pkg/minikube/cluster/commands_test.go | 12 ++++-------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/localkube/cmd/root.go b/cmd/localkube/cmd/root.go index ba265a0f88..5e38ee05c7 100644 --- a/cmd/localkube/cmd/root.go +++ b/cmd/localkube/cmd/root.go @@ -17,7 +17,10 @@ limitations under the License. package cmd import ( + goflag "flag" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) var RootCmd = &cobra.Command{ @@ -27,6 +30,7 @@ var RootCmd = &cobra.Command{ } func init() { + pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) cobra.OnInitialize(initConfig) } diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 85d743b0d9..a2f60febfb 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -151,6 +151,7 @@ func StartCluster(h sshAble) error { commands := []string{stopCommand, GetStartCommand()} for _, cmd := range commands { + glog.Infoln(cmd) output, err := h.RunSSHCommand(cmd) glog.Infoln(output) if err != nil { diff --git a/pkg/minikube/cluster/commands.go b/pkg/minikube/cluster/commands.go index ab8d5f0ede..730ef5d44f 100644 --- a/pkg/minikube/cluster/commands.go +++ b/pkg/minikube/cluster/commands.go @@ -29,17 +29,12 @@ const ( remoteLocalKubeOutPath = "/var/log/localkube.out" ) -var startCommand = ` -# Run with nohup so it stays up. Redirect logs to useful places. -PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start --generate-certs=false > /var/log/localkube.out 2> /var/log/localkube.err < /dev/null & -` - // Kill any running instances. -var stopCommand = "killall localkube | true" +var stopCommand = "sudo killall localkube | true" var startCommandFmtStr = ` # Run with nohup so it stays up. Redirect logs to useful places. -PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start %s--generate-certs=false > %s 2> %s < /dev/null & +PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start %s --generate-certs=false > %s 2> %s < /dev/null & ` var logsCommand = fmt.Sprintf("tail -n +1 %s %s", remoteLocalKubeErrPath, remoteLocalKubeOutPath) @@ -47,7 +42,7 @@ var logsCommand = fmt.Sprintf("tail -n +1 %s %s", remoteLocalKubeErrPath, remote func GetStartCommand() string { flagVals := make([]string, len(constants.LogFlags)) for _, logFlag := range constants.LogFlags { - if logVal := gflag.Lookup(logFlag); logVal != nil && logVal.Value.String() != "" { + if logVal := gflag.Lookup(logFlag); logVal != nil && logVal.Value.String() != logVal.DefValue { flagVals = append(flagVals, fmt.Sprintf("--%s %s", logFlag, logVal.Value.String())) } } diff --git a/pkg/minikube/cluster/commands_test.go b/pkg/minikube/cluster/commands_test.go index d495b3aa8f..69db5fcffa 100644 --- a/pkg/minikube/cluster/commands_test.go +++ b/pkg/minikube/cluster/commands_test.go @@ -24,21 +24,17 @@ import ( ) func TestGetStartCommandDefaultValues(t *testing.T) { + // Stderr threshold is the only value that should be printed by default, because it's not set using the standard + // flag default value system in glog.go flagMap := map[string]string{ - "logtostderr": "false", - "alsologtostderr": "false", - "stderrthreshold": "2", - "log_dir": "", - "log_backtrace_at": ":0", - "v": "0", - "vmodule": "", + "stderrthreshold": "2", } flagMapToSetFlags(flagMap) startCommand := GetStartCommand() for flag, val := range flagMap { if val != "" { if expectedFlag := getSingleFlagValue(flag, val); !strings.Contains(startCommand, getSingleFlagValue(flag, val)) { - t.Fatalf("Expected GetStartCommand to contain: %s.", expectedFlag) + t.Fatalf("Expected GetStartCommand to contain: %s. Command was: %s", expectedFlag, startCommand) } } }