Merge pull request #120 from aaron-prindle/glog
Added glog in place of log.*-and-fmt.Error* for cmd/minikube,pull/125/head
commit
f65133678f
|
@ -18,10 +18,10 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
|
@ -38,7 +38,7 @@ var dockerEnvCmd = &cobra.Command{
|
|||
|
||||
envMap, err := cluster.GetHostDockerEnv(api)
|
||||
if err != nil {
|
||||
log.Println("Error setting machine env variable(s):", err)
|
||||
glog.Errorln("Error setting machine env variable(s):", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintln(os.Stdout, buildDockerEnvShellOutput(envMap))
|
||||
|
|
|
@ -18,10 +18,10 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -37,12 +37,12 @@ var ipCmd = &cobra.Command{
|
|||
defer api.Close()
|
||||
host, err := api.Load(constants.MachineName)
|
||||
if err != nil {
|
||||
log.Println("Error getting IP: ", err)
|
||||
glog.Errorln("Error getting IP: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
ip, err := host.Driver.GetIP()
|
||||
if err != nil {
|
||||
log.Println("Error getting IP: ", err)
|
||||
glog.Errorln("Error getting IP: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(ip)
|
||||
|
|
|
@ -17,11 +17,12 @@ limitations under the License.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
goflag "flag"
|
||||
"os"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
|
@ -38,7 +39,7 @@ var RootCmd = &cobra.Command{
|
|||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
for _, path := range dirs {
|
||||
if err := os.MkdirAll(path, 0777); err != nil {
|
||||
log.Panicf("Error creating minikube directory: %s", err)
|
||||
glog.Exitf("Error creating minikube directory: %s", err)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -48,12 +49,12 @@ var RootCmd = &cobra.Command{
|
|||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
glog.Exitln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
cobra.OnInitialize(initConfig)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
cfg "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
|
@ -30,6 +30,10 @@ import (
|
|||
"k8s.io/minikube/pkg/minikube/kubeconfig"
|
||||
)
|
||||
|
||||
var (
|
||||
minikubeISO string
|
||||
)
|
||||
|
||||
// startCmd represents the start command
|
||||
var startCmd = &cobra.Command{
|
||||
Use: "start",
|
||||
|
@ -39,12 +43,7 @@ assumes you already have Virtualbox installed.`,
|
|||
Run: runStart,
|
||||
}
|
||||
|
||||
var (
|
||||
minikubeISO string
|
||||
)
|
||||
|
||||
func runStart(cmd *cobra.Command, args []string) {
|
||||
|
||||
fmt.Println("Starting local Kubernetes cluster...")
|
||||
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
|
||||
defer api.Close()
|
||||
|
@ -54,29 +53,30 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
host, err := cluster.StartHost(api, config)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Error starting host: ", err)
|
||||
glog.Errorln("Error starting host: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := cluster.UpdateCluster(host.Driver); err != nil {
|
||||
log.Println("Error updating cluster: ", err)
|
||||
glog.Errorln("Error updating cluster: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := cluster.SetupCerts(host.Driver); err != nil {
|
||||
log.Println("Error configuring authentication: ", err)
|
||||
glog.Errorln("Error configuring authentication: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := cluster.StartCluster(host); err != nil {
|
||||
log.Println("Error starting cluster: ", err)
|
||||
glog.Errorln("Error starting cluster: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
kubeHost, err := host.Driver.GetURL()
|
||||
if err != nil {
|
||||
log.Println("Error connecting to cluster: ", err)
|
||||
glog.Errorln("Error connecting to cluster: ", err)
|
||||
}
|
||||
kubeHost = strings.Replace(kubeHost, "tcp://", "https://", -1)
|
||||
kubeHost = strings.Replace(kubeHost, ":2376", ":443", -1)
|
||||
|
@ -88,7 +88,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
clientCert := constants.MakeMiniPath("apiserver.crt")
|
||||
clientKey := constants.MakeMiniPath("apiserver.key")
|
||||
if active, err := setupKubeconfig(name, kubeHost, certAuth, clientCert, clientKey); err != nil {
|
||||
log.Println("Error setting up kubeconfig: ", err)
|
||||
glog.Errorln("Error setting up kubeconfig: ", err)
|
||||
os.Exit(1)
|
||||
} else if !active {
|
||||
fmt.Println("Run this command to use the cluster: ")
|
||||
|
|
|
@ -18,10 +18,10 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
|
@ -37,7 +37,7 @@ var statusCmd = &cobra.Command{
|
|||
defer api.Close()
|
||||
s, err := cluster.GetHostStatus(api)
|
||||
if err != nil {
|
||||
log.Println("Error getting machine status:", err)
|
||||
glog.Errorln("Error getting machine status:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintln(os.Stdout, s)
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -31,6 +30,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/sshutil"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
|
@ -45,7 +45,7 @@ func StartHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
|
|||
if exists, err := api.Exists(constants.MachineName); err != nil {
|
||||
return nil, fmt.Errorf("Error checking if host exists: %s", err)
|
||||
} else if exists {
|
||||
log.Println("Machine exists!")
|
||||
glog.Infoln("Machine exists!")
|
||||
h, err := api.Load(constants.MachineName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error loading existing host: %s", err)
|
||||
|
@ -148,11 +148,11 @@ type MachineConfig struct {
|
|||
|
||||
// StartCluster starts a k8s cluster on the specified Host.
|
||||
func StartCluster(h sshAble) error {
|
||||
commands := []string{stopCommand, startCommand}
|
||||
commands := []string{stopCommand, GetStartCommand()}
|
||||
|
||||
for _, cmd := range commands {
|
||||
output, err := h.RunSSHCommand(cmd)
|
||||
log.Println(output)
|
||||
glog.Infoln(output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func StartCluster(h sshAble) error {
|
|||
func UpdateCluster(d drivers.Driver) error {
|
||||
localkube, err := Asset("out/localkube")
|
||||
if err != nil {
|
||||
log.Println("Error loading localkube: ", err)
|
||||
glog.Infoln("Error loading localkube: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ func TestStartCluster(t *testing.T) {
|
|||
t.Fatalf("Error starting cluster: %s", err)
|
||||
}
|
||||
|
||||
for _, cmd := range []string{stopCommand, startCommand} {
|
||||
for _, cmd := range []string{stopCommand, GetStartCommand()} {
|
||||
if _, ok := h.Commands[cmd]; !ok {
|
||||
t.Fatalf("Expected command not run: %s. Commands run: %s", cmd, h.Commands)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,13 @@ limitations under the License.
|
|||
|
||||
package cluster
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
gflag "flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
const (
|
||||
remoteLocalKubeErrPath = "/var/log/localkube.err"
|
||||
|
@ -29,6 +35,22 @@ PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start --generate-
|
|||
`
|
||||
|
||||
// Kill any running instances.
|
||||
var stopCommand = "sudo killall localkube | true"
|
||||
var stopCommand = "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 &
|
||||
`
|
||||
|
||||
var logsCommand = fmt.Sprintf("tail -n +1 %s %s", remoteLocalKubeErrPath, remoteLocalKubeOutPath)
|
||||
|
||||
func GetStartCommand() string {
|
||||
flagVals := make([]string, len(constants.LogFlags))
|
||||
for _, logFlag := range constants.LogFlags {
|
||||
if logVal := gflag.Lookup(logFlag); logVal != nil && logVal.Value.String() != "" {
|
||||
flagVals = append(flagVals, fmt.Sprintf("--%s %s", logFlag, logVal.Value.String()))
|
||||
}
|
||||
}
|
||||
flags := strings.Join(flagVals, " ")
|
||||
return fmt.Sprintf(startCommandFmtStr, flags, remoteLocalKubeErrPath, remoteLocalKubeOutPath)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
|
||||
import (
|
||||
gflag "flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetStartCommandDefaultValues(t *testing.T) {
|
||||
flagMap := map[string]string{
|
||||
"logtostderr": "false",
|
||||
"alsologtostderr": "false",
|
||||
"stderrthreshold": "2",
|
||||
"log_dir": "",
|
||||
"log_backtrace_at": ":0",
|
||||
"v": "0",
|
||||
"vmodule": "",
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStartCommandCustomValues(t *testing.T) {
|
||||
flagMap := map[string]string{
|
||||
"logtostderr": "true",
|
||||
"alsologtostderr": "true",
|
||||
"stderrthreshold": "3",
|
||||
"log_dir": "/var/",
|
||||
"log_backtrace_at": "cluster.go:123",
|
||||
"v": "10",
|
||||
"vmodule": "cluster*=5",
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func flagMapToSetFlags(flagMap map[string]string) {
|
||||
for flag, val := range flagMap {
|
||||
gflag.Set(flag, val)
|
||||
}
|
||||
}
|
||||
func getSingleFlagValue(flag, val string) string {
|
||||
return fmt.Sprintf("--%s %s", flag, val)
|
||||
}
|
|
@ -39,4 +39,14 @@ func MakeMiniPath(fileName string) string {
|
|||
return filepath.Join(Minipath, fileName)
|
||||
}
|
||||
|
||||
var LogFlags = [...]string{
|
||||
"logtostderr",
|
||||
"alsologtostderr",
|
||||
"stderrthreshold",
|
||||
"log_dir",
|
||||
"log_backtrace_at",
|
||||
"v",
|
||||
"vmodule",
|
||||
}
|
||||
|
||||
const DefaultIsoUrl = "https://storage.googleapis.com/minikube/minikube-0.1.iso"
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
@ -61,7 +62,7 @@ func ReadConfigOrNew(filename string) (*api.Config, error) {
|
|||
// If the file exists, it's contents will be overwritten.
|
||||
func WriteConfig(config *api.Config, filename string) error {
|
||||
if config == nil {
|
||||
fmt.Errorf("could not write to '%s': config can't be nil", filename)
|
||||
glog.Errorf("could not write to '%s': config can't be nil", filename)
|
||||
}
|
||||
|
||||
// encode config to YAML
|
||||
|
|
|
@ -17,12 +17,12 @@ limitations under the License.
|
|||
package machine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// StartDriver starts the desired machine driver if necessary.
|
||||
|
@ -33,8 +33,7 @@ func StartDriver() {
|
|||
case "virtualbox":
|
||||
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "Unsupported driver: %s\n", driverName)
|
||||
os.Exit(1)
|
||||
glog.Exitf("Unsupported driver: %s\n", driverName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue