Allow glog flags in localkube.
parent
f65133678f
commit
abca78dfde
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue