Skip to content

Commit

Permalink
Merge pull request #5679 from afbjorklund/reportcard-again
Browse files Browse the repository at this point in the history
Reportcard again, golint and gocyclo.
  • Loading branch information
afbjorklund authored Nov 2, 2019
2 parents 5193850 + 47fe5b2 commit 134182f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 103 deletions.
21 changes: 16 additions & 5 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ func runDelete(cmd *cobra.Command, args []string) {

// If the purge flag is set, go ahead and delete the .minikube directory.
if purge {
glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath())
if err := os.RemoveAll(localpath.MiniPath()); err != nil {
exit.WithError("unable to delete minikube config folder", err)
}
out.T(out.Crushed, "Successfully purged minikube directory located at - [{{.minikubeDirectory}}]", out.V{"minikubeDirectory": localpath.MiniPath()})
purgeMinikubeDirectory()
}
}

func purgeMinikubeDirectory() {
glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath())
if err := os.RemoveAll(localpath.MiniPath()); err != nil {
exit.WithError("unable to delete minikube config folder", err)
}
out.T(out.Crushed, "Successfully purged minikube directory located at - [{{.minikubeDirectory}}]", out.V{"minikubeDirectory": localpath.MiniPath()})
}

// DeleteProfiles deletes one or more profiles
Expand Down Expand Up @@ -232,6 +236,13 @@ func deleteProfile(profile *pkg_config.Profile) error {
out.T(out.Crushed, `The "{{.name}}" cluster has been deleted.`, out.V{"name": profile.Name})

machineName := pkg_config.GetMachineName()
if err := deleteContext(machineName); err != nil {
return err
}
return nil
}

func deleteContext(machineName string) error {
if err := kubeconfig.DeleteContext(constants.KubeconfigPath, machineName); err != nil {
return DeletionError{Err: fmt.Errorf("update config: %v", err), Errtype: Fatal}
}
Expand Down
66 changes: 44 additions & 22 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,7 @@ func runStart(cmd *cobra.Command, args []string) {

// No need to install a driver in download-only mode
if !viper.GetBool(downloadOnly) {
v, err := version.GetSemverVersion()
if err != nil {
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
} else if err := driver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
}
updateDriver(driverName)
}

k8sVersion, isUpgrade := getKubernetesVersion(oldConfig)
Expand Down Expand Up @@ -360,12 +355,7 @@ func runStart(cmd *cobra.Command, args []string) {
configureMounts()

// enable addons with start command
for _, a := range addonList {
err = cmdcfg.Set(a, "true")
if err != nil {
exit.WithError("addon enable failed", err)
}
}
enableAddons()

if err = loadCachedImagesInConfigFile(); err != nil {
out.T(out.FailureType, "Unable to load cached images from config file.")
Expand All @@ -375,7 +365,31 @@ func runStart(cmd *cobra.Command, args []string) {
if driverName == driver.None {
prepareNone()
}
waitCluster(bs, config)
if err := showKubectlInfo(kubeconfig, k8sVersion); err != nil {
glog.Errorf("kubectl info: %v", err)
}
}

func updateDriver(driverName string) {
v, err := version.GetSemverVersion()
if err != nil {
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
} else if err := driver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
}
}

func enableAddons() {
for _, a := range addonList {
err := cmdcfg.Set(a, "true")
if err != nil {
exit.WithError("addon enable failed", err)
}
}
}

func waitCluster(bs bootstrapper.Bootstrapper, config cfg.Config) {
var podsToWaitFor []string

if !viper.GetBool(waitUntilHealthy) {
Expand All @@ -385,9 +399,6 @@ func runStart(cmd *cobra.Command, args []string) {
if err := bs.WaitForPods(config.KubernetesConfig, viper.GetDuration(waitTimeout), podsToWaitFor); err != nil {
exit.WithError("Wait failed", err)
}
if err := showKubectlInfo(kubeconfig, k8sVersion); err != nil {
glog.Errorf("kubectl info: %v", err)
}
}

func displayVersion(version string) {
Expand Down Expand Up @@ -1009,10 +1020,19 @@ func validateNetwork(h *host.Host, r command.Runner) string {
}

if !driver.BareMetal(h.Driver.DriverName()) {
sshAddr := fmt.Sprintf("%s:22", ip)
conn, err := net.Dial("tcp", sshAddr)
if err != nil {
exit.WithCodeT(exit.IO, `minikube is unable to connect to the VM: {{.error}}
trySSH(h, ip)
}

tryLookup(r)
tryRegistry(r)
return ip
}

func trySSH(h *host.Host, ip string) {
sshAddr := fmt.Sprintf("%s:22", ip)
conn, err := net.Dial("tcp", sshAddr)
if err != nil {
exit.WithCodeT(exit.IO, `minikube is unable to connect to the VM: {{.error}}
This is likely due to one of two reasons:
Expand All @@ -1025,16 +1045,19 @@ Suggested workarounds:
- Configure your local VPN or firewall to allow access to {{.ip}}
- Restart or reinstall {{.hypervisor}}
- Use an alternative --vm-driver`, out.V{"error": err, "hypervisor": h.Driver.DriverName(), "ip": ip})
}
defer conn.Close()
}
defer conn.Close()
}

func tryLookup(r command.Runner) {
// DNS check
if rr, err := r.RunCmd(exec.Command("nslookup", "kubernetes.io")); err != nil {
glog.Warningf("%s failed: %v", rr.Args, err)
out.WarningT("VM may be unable to resolve external DNS records")
}
}

func tryRegistry(r command.Runner) {
// Try an HTTPS connection to the image repository
proxy := os.Getenv("HTTPS_PROXY")
opts := []string{"-sS"}
Expand All @@ -1052,7 +1075,6 @@ Suggested workarounds:
glog.Warningf("%s failed: %v", rr.Args, err)
out.WarningT("VM is unable to access {{.repository}}, you may need to configure a proxy or set --image-repository", out.V{"repository": repo})
}
return ip
}

// getKubernetesVersion ensures that the requested version is reasonable
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
var statusFormat string
var output string

// KubeconfigStatus represents the kubeconfig status
var KubeconfigStatus = struct {
Configured string
Misconfigured string
Expand Down
87 changes: 20 additions & 67 deletions pkg/minikube/cruntime/cruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func NewFakeRunner(t *testing.T) *FakeRunner {
}
}

func buffer(s string, err error) (*command.RunResult, error) {
rr := &command.RunResult{}
if err != nil {
return rr, err
}
var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing outStr to FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err
}

// Run a fake command!
func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
xargs := cmd.Args
Expand All @@ -127,77 +142,15 @@ func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
}
switch bin {
case "systemctl":
s, err := f.systemctl(args, root)
rr := &command.RunResult{}
if err != nil {
return rr, err
}
var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing outStr to FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err
return buffer(f.systemctl(args, root))
case "docker":
s, err := f.docker(args, root)
rr := &command.RunResult{}
if err != nil {
return rr, err
}
var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err

return buffer(f.docker(args, root))
case "crictl":
s, err := f.crictl(args, root)
rr := &command.RunResult{}
if err != nil {
return rr, err
}
var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err
return buffer(f.crictl(args, root))
case "crio":
s, err := f.crio(args, root)
rr := &command.RunResult{}
if err != nil {
return rr, err
}
var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err
return buffer(f.crio(args, root))
case "containerd":
s, err := f.containerd(args, root)
rr := &command.RunResult{}
if err != nil {
return rr, err
}

var buf bytes.Buffer
_, err = buf.WriteString(s)
if err != nil {
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
}
rr.Stdout = buf
rr.Stderr = buf
return rr, err
return buffer(f.containerd(args, root))
default:
rr := &command.RunResult{}
return rr, nil
Expand Down
25 changes: 17 additions & 8 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ import (
)

const (
Mock = "mock"
None = "none"
KVM2 = "kvm2"
VirtualBox = "virtualbox"
HyperKit = "hyperkit"
VMware = "vmware"
// Mock driver
Mock = "mock"
// None driver
None = "none"
// KVM2 driver
KVM2 = "kvm2"
// VirtualBox driver
VirtualBox = "virtualbox"
// HyperKit driver
HyperKit = "hyperkit"
// VMware driver
VMware = "vmware"
// VMwareFusion driver
VMwareFusion = "vmwarefusion"
HyperV = "hyperv"
Parallels = "parallels"
// HyperV driver
HyperV = "hyperv"
// Parallels driver
Parallels = "parallels"
)

var (
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/driver/driver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var supportedDrivers = []string{
None,
}

// VBoxManagePath returns the path to the VBoxManage command
func VBoxManagePath() string {
cmd := "VBoxManage"
if path, err := exec.LookPath(cmd); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/registry/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGlobalInstalled(t *testing.T) {
}

expected := []DriverState{
DriverState{
{
Name: "bar",
Priority: Default,
State: State{
Expand Down
7 changes: 7 additions & 0 deletions pkg/minikube/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ import (
type Priority int

const (
// Unknown priority
Unknown Priority = iota
// Discouraged priority
Discouraged
// Deprecated priority
Deprecated
// Fallback priority
Fallback
// Default priority
Default
// Preferred priority
Preferred
// StronglyPreferred priority
StronglyPreferred
)

Expand Down

0 comments on commit 134182f

Please sign in to comment.