Merge pull request #5679 from afbjorklund/reportcard-again
Reportcard again, golint and gocyclo.pull/5816/head
commit
134182fab5
|
@ -144,14 +144,18 @@ 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
|
||||
func DeleteProfiles(profiles []*pkg_config.Profile) []error {
|
||||
var errs []error
|
||||
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -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.")
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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"}
|
||||
|
@ -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
|
||||
|
|
|
@ -40,6 +40,7 @@ import (
|
|||
var statusFormat string
|
||||
var output string
|
||||
|
||||
// KubeconfigStatus represents the kubeconfig status
|
||||
var KubeconfigStatus = struct {
|
||||
Configured string
|
||||
Misconfigured string
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestGlobalInstalled(t *testing.T) {
|
|||
}
|
||||
|
||||
expected := []DriverState{
|
||||
DriverState{
|
||||
{
|
||||
Name: "bar",
|
||||
Priority: Default,
|
||||
State: State{
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue