Skip to content

Commit 134182f

Browse files
authored
Merge pull request #5679 from afbjorklund/reportcard-again
Reportcard again, golint and gocyclo.
2 parents 5193850 + 47fe5b2 commit 134182f

File tree

8 files changed

+107
-103
lines changed

8 files changed

+107
-103
lines changed

cmd/minikube/cmd/delete.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ func runDelete(cmd *cobra.Command, args []string) {
144144

145145
// If the purge flag is set, go ahead and delete the .minikube directory.
146146
if purge {
147-
glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath())
148-
if err := os.RemoveAll(localpath.MiniPath()); err != nil {
149-
exit.WithError("unable to delete minikube config folder", err)
150-
}
151-
out.T(out.Crushed, "Successfully purged minikube directory located at - [{{.minikubeDirectory}}]", out.V{"minikubeDirectory": localpath.MiniPath()})
147+
purgeMinikubeDirectory()
148+
}
149+
}
150+
151+
func purgeMinikubeDirectory() {
152+
glog.Infof("Purging the '.minikube' directory located at %s", localpath.MiniPath())
153+
if err := os.RemoveAll(localpath.MiniPath()); err != nil {
154+
exit.WithError("unable to delete minikube config folder", err)
152155
}
156+
out.T(out.Crushed, "Successfully purged minikube directory located at - [{{.minikubeDirectory}}]", out.V{"minikubeDirectory": localpath.MiniPath()})
153157
}
154158

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

234238
machineName := pkg_config.GetMachineName()
239+
if err := deleteContext(machineName); err != nil {
240+
return err
241+
}
242+
return nil
243+
}
244+
245+
func deleteContext(machineName string) error {
235246
if err := kubeconfig.DeleteContext(constants.KubeconfigPath, machineName); err != nil {
236247
return DeletionError{Err: fmt.Errorf("update config: %v", err), Errtype: Fatal}
237248
}

cmd/minikube/cmd/start.go

+44-22
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,7 @@ func runStart(cmd *cobra.Command, args []string) {
301301

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

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

362357
// enable addons with start command
363-
for _, a := range addonList {
364-
err = cmdcfg.Set(a, "true")
365-
if err != nil {
366-
exit.WithError("addon enable failed", err)
367-
}
368-
}
358+
enableAddons()
369359

370360
if err = loadCachedImagesInConfigFile(); err != nil {
371361
out.T(out.FailureType, "Unable to load cached images from config file.")
@@ -375,7 +365,31 @@ func runStart(cmd *cobra.Command, args []string) {
375365
if driverName == driver.None {
376366
prepareNone()
377367
}
368+
waitCluster(bs, config)
369+
if err := showKubectlInfo(kubeconfig, k8sVersion); err != nil {
370+
glog.Errorf("kubectl info: %v", err)
371+
}
372+
}
373+
374+
func updateDriver(driverName string) {
375+
v, err := version.GetSemverVersion()
376+
if err != nil {
377+
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
378+
} else if err := driver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
379+
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
380+
}
381+
}
382+
383+
func enableAddons() {
384+
for _, a := range addonList {
385+
err := cmdcfg.Set(a, "true")
386+
if err != nil {
387+
exit.WithError("addon enable failed", err)
388+
}
389+
}
390+
}
378391

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

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

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

10111022
if !driver.BareMetal(h.Driver.DriverName()) {
1012-
sshAddr := fmt.Sprintf("%s:22", ip)
1013-
conn, err := net.Dial("tcp", sshAddr)
1014-
if err != nil {
1015-
exit.WithCodeT(exit.IO, `minikube is unable to connect to the VM: {{.error}}
1023+
trySSH(h, ip)
1024+
}
1025+
1026+
tryLookup(r)
1027+
tryRegistry(r)
1028+
return ip
1029+
}
1030+
1031+
func trySSH(h *host.Host, ip string) {
1032+
sshAddr := fmt.Sprintf("%s:22", ip)
1033+
conn, err := net.Dial("tcp", sshAddr)
1034+
if err != nil {
1035+
exit.WithCodeT(exit.IO, `minikube is unable to connect to the VM: {{.error}}
10161036
10171037
This is likely due to one of two reasons:
10181038
@@ -1025,16 +1045,19 @@ Suggested workarounds:
10251045
- Configure your local VPN or firewall to allow access to {{.ip}}
10261046
- Restart or reinstall {{.hypervisor}}
10271047
- Use an alternative --vm-driver`, out.V{"error": err, "hypervisor": h.Driver.DriverName(), "ip": ip})
1028-
}
1029-
defer conn.Close()
10301048
}
1049+
defer conn.Close()
1050+
}
10311051

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

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

10581080
// getKubernetesVersion ensures that the requested version is reasonable

cmd/minikube/cmd/status.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
var statusFormat string
4141
var output string
4242

43+
// KubeconfigStatus represents the kubeconfig status
4344
var KubeconfigStatus = struct {
4445
Configured string
4546
Misconfigured string

pkg/minikube/cruntime/cruntime_test.go

+20-67
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ func NewFakeRunner(t *testing.T) *FakeRunner {
114114
}
115115
}
116116

117+
func buffer(s string, err error) (*command.RunResult, error) {
118+
rr := &command.RunResult{}
119+
if err != nil {
120+
return rr, err
121+
}
122+
var buf bytes.Buffer
123+
_, err = buf.WriteString(s)
124+
if err != nil {
125+
return rr, errors.Wrap(err, "Writing outStr to FakeRunner's buffer")
126+
}
127+
rr.Stdout = buf
128+
rr.Stderr = buf
129+
return rr, err
130+
}
131+
117132
// Run a fake command!
118133
func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
119134
xargs := cmd.Args
@@ -127,77 +142,15 @@ func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
127142
}
128143
switch bin {
129144
case "systemctl":
130-
s, err := f.systemctl(args, root)
131-
rr := &command.RunResult{}
132-
if err != nil {
133-
return rr, err
134-
}
135-
var buf bytes.Buffer
136-
_, err = buf.WriteString(s)
137-
if err != nil {
138-
return rr, errors.Wrap(err, "Writing outStr to FakeRunner's buffer")
139-
}
140-
rr.Stdout = buf
141-
rr.Stderr = buf
142-
return rr, err
145+
return buffer(f.systemctl(args, root))
143146
case "docker":
144-
s, err := f.docker(args, root)
145-
rr := &command.RunResult{}
146-
if err != nil {
147-
return rr, err
148-
}
149-
var buf bytes.Buffer
150-
_, err = buf.WriteString(s)
151-
if err != nil {
152-
return rr, errors.Wrap(err, "Writing FakeRunner's buffer")
153-
}
154-
rr.Stdout = buf
155-
rr.Stderr = buf
156-
return rr, err
157-
147+
return buffer(f.docker(args, root))
158148
case "crictl":
159-
s, err := f.crictl(args, root)
160-
rr := &command.RunResult{}
161-
if err != nil {
162-
return rr, err
163-
}
164-
var buf bytes.Buffer
165-
_, err = buf.WriteString(s)
166-
if err != nil {
167-
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
168-
}
169-
rr.Stdout = buf
170-
rr.Stderr = buf
171-
return rr, err
149+
return buffer(f.crictl(args, root))
172150
case "crio":
173-
s, err := f.crio(args, root)
174-
rr := &command.RunResult{}
175-
if err != nil {
176-
return rr, err
177-
}
178-
var buf bytes.Buffer
179-
_, err = buf.WriteString(s)
180-
if err != nil {
181-
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
182-
}
183-
rr.Stdout = buf
184-
rr.Stderr = buf
185-
return rr, err
151+
return buffer(f.crio(args, root))
186152
case "containerd":
187-
s, err := f.containerd(args, root)
188-
rr := &command.RunResult{}
189-
if err != nil {
190-
return rr, err
191-
}
192-
193-
var buf bytes.Buffer
194-
_, err = buf.WriteString(s)
195-
if err != nil {
196-
return rr, errors.Wrap(err, "Writing to FakeRunner's buffer")
197-
}
198-
rr.Stdout = buf
199-
rr.Stderr = buf
200-
return rr, err
153+
return buffer(f.containerd(args, root))
201154
default:
202155
rr := &command.RunResult{}
203156
return rr, nil

pkg/minikube/driver/driver.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ import (
2626
)
2727

2828
const (
29-
Mock = "mock"
30-
None = "none"
31-
KVM2 = "kvm2"
32-
VirtualBox = "virtualbox"
33-
HyperKit = "hyperkit"
34-
VMware = "vmware"
29+
// Mock driver
30+
Mock = "mock"
31+
// None driver
32+
None = "none"
33+
// KVM2 driver
34+
KVM2 = "kvm2"
35+
// VirtualBox driver
36+
VirtualBox = "virtualbox"
37+
// HyperKit driver
38+
HyperKit = "hyperkit"
39+
// VMware driver
40+
VMware = "vmware"
41+
// VMwareFusion driver
3542
VMwareFusion = "vmwarefusion"
36-
HyperV = "hyperv"
37-
Parallels = "parallels"
43+
// HyperV driver
44+
HyperV = "hyperv"
45+
// Parallels driver
46+
Parallels = "parallels"
3847
)
3948

4049
var (

pkg/minikube/driver/driver_linux.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var supportedDrivers = []string{
3030
None,
3131
}
3232

33+
// VBoxManagePath returns the path to the VBoxManage command
3334
func VBoxManagePath() string {
3435
cmd := "VBoxManage"
3536
if path, err := exec.LookPath(cmd); err == nil {

pkg/minikube/registry/global_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestGlobalInstalled(t *testing.T) {
8181
}
8282

8383
expected := []DriverState{
84-
DriverState{
84+
{
8585
Name: "bar",
8686
Priority: Default,
8787
State: State{

pkg/minikube/registry/registry.go

+7
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ import (
2929
type Priority int
3030

3131
const (
32+
// Unknown priority
3233
Unknown Priority = iota
34+
// Discouraged priority
3335
Discouraged
36+
// Deprecated priority
3437
Deprecated
38+
// Fallback priority
3539
Fallback
40+
// Default priority
3641
Default
42+
// Preferred priority
3743
Preferred
44+
// StronglyPreferred priority
3845
StronglyPreferred
3946
)
4047

0 commit comments

Comments
 (0)