Allow glog flags in localkube.
parent
f65133678f
commit
abca78dfde
|
@ -17,7 +17,10 @@ limitations under the License.
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
goflag "flag"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
|
@ -27,6 +30,7 @@ var RootCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,7 @@ func StartCluster(h sshAble) error {
|
||||||
commands := []string{stopCommand, GetStartCommand()}
|
commands := []string{stopCommand, GetStartCommand()}
|
||||||
|
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
|
glog.Infoln(cmd)
|
||||||
output, err := h.RunSSHCommand(cmd)
|
output, err := h.RunSSHCommand(cmd)
|
||||||
glog.Infoln(output)
|
glog.Infoln(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -29,13 +29,8 @@ const (
|
||||||
remoteLocalKubeOutPath = "/var/log/localkube.out"
|
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.
|
// Kill any running instances.
|
||||||
var stopCommand = "killall localkube | true"
|
var stopCommand = "sudo killall localkube | true"
|
||||||
|
|
||||||
var startCommandFmtStr = `
|
var startCommandFmtStr = `
|
||||||
# Run with nohup so it stays up. Redirect logs to useful places.
|
# Run with nohup so it stays up. Redirect logs to useful places.
|
||||||
|
@ -47,7 +42,7 @@ var logsCommand = fmt.Sprintf("tail -n +1 %s %s", remoteLocalKubeErrPath, remote
|
||||||
func GetStartCommand() string {
|
func GetStartCommand() string {
|
||||||
flagVals := make([]string, len(constants.LogFlags))
|
flagVals := make([]string, len(constants.LogFlags))
|
||||||
for _, logFlag := range 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()))
|
flagVals = append(flagVals, fmt.Sprintf("--%s %s", logFlag, logVal.Value.String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetStartCommandDefaultValues(t *testing.T) {
|
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{
|
flagMap := map[string]string{
|
||||||
"logtostderr": "false",
|
|
||||||
"alsologtostderr": "false",
|
|
||||||
"stderrthreshold": "2",
|
"stderrthreshold": "2",
|
||||||
"log_dir": "",
|
|
||||||
"log_backtrace_at": ":0",
|
|
||||||
"v": "0",
|
|
||||||
"vmodule": "",
|
|
||||||
}
|
}
|
||||||
flagMapToSetFlags(flagMap)
|
flagMapToSetFlags(flagMap)
|
||||||
startCommand := GetStartCommand()
|
startCommand := GetStartCommand()
|
||||||
for flag, val := range flagMap {
|
for flag, val := range flagMap {
|
||||||
if val != "" {
|
if val != "" {
|
||||||
if expectedFlag := getSingleFlagValue(flag, val); !strings.Contains(startCommand, getSingleFlagValue(flag, 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