Skip to content

Commit 75ba4c2

Browse files
authored
Merge pull request #7043 from tstromberg/lz4-missing
Delete: output underlying status failure, better machine function names
2 parents df44b7b + 8959672 commit 75ba4c2

25 files changed

+93
-155
lines changed

cmd/minikube/cmd/config/open.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var addonsOpenCmd = &cobra.Command{
7878
if err != nil {
7979
exit.WithError("Error getting control plane", err)
8080
}
81-
if !machine.IsHostRunning(api, driver.MachineName(*cc, cp)) {
81+
if !machine.IsRunning(api, driver.MachineName(*cc, cp)) {
8282
os.Exit(1)
8383
}
8484
addon, ok := assets.Addons[addonName] // validate addon input

cmd/minikube/cmd/config/profile_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var printProfilesTable = func() {
8080
if err != nil {
8181
exit.WithError("error getting primary control plane", err)
8282
}
83-
p.Status, err = machine.GetHostStatus(api, driver.MachineName(*p.Config, cp))
83+
p.Status, err = machine.Status(api, driver.MachineName(*p.Config, cp))
8484
if err != nil {
8585
glog.Warningf("error getting host status for %s: %v", p.Name, err)
8686
}
@@ -121,7 +121,7 @@ var printProfilesJSON = func() {
121121
if err != nil {
122122
exit.WithError("error getting primary control plane", err)
123123
}
124-
status, err := machine.GetHostStatus(api, driver.MachineName(*v.Config, cp))
124+
status, err := machine.Status(api, driver.MachineName(*v.Config, cp))
125125
if err != nil {
126126
glog.Warningf("error getting host status for %s: %v", v.Name, err)
127127
}

cmd/minikube/cmd/dashboard.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var dashboardCmd = &cobra.Command{
109109
exit.WithCodeT(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
110110
}
111111

112-
if !machine.IsHostRunning(api, machineName) {
112+
if !machine.IsRunning(api, machineName) {
113113
os.Exit(1)
114114
}
115115

cmd/minikube/cmd/delete.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func DeleteProfiles(profiles []*config.Profile) []error {
174174
err := deleteProfile(profile)
175175

176176
if err != nil {
177-
mm, loadErr := machine.Load(profile.Name)
177+
mm, loadErr := machine.LoadMachine(profile.Name)
178178

179179
if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
180180
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
@@ -208,7 +208,6 @@ func deleteProfileContainersAndVolumes(name string) {
208208

209209
func deleteProfile(profile *config.Profile) error {
210210
viper.Set(config.ProfileName, profile.Name)
211-
212211
deleteProfileContainersAndVolumes(profile.Name)
213212

214213
api, err := machine.NewAPIClient()
@@ -217,6 +216,7 @@ func deleteProfile(profile *config.Profile) error {
217216
return DeletionError{Err: delErr, Errtype: Fatal}
218217
}
219218
defer api.Close()
219+
220220
cc, err := config.Load(profile.Name)
221221
if err != nil && !config.IsNotExist(err) {
222222
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("error loading profile config: %v", err))
@@ -328,7 +328,7 @@ func uninstallKubernetes(api libmachine.API, cc config.ClusterConfig, n config.N
328328
return DeletionError{Err: fmt.Errorf("unable to get bootstrapper: %v", err), Errtype: Fatal}
329329
}
330330

331-
host, err := machine.CheckIfHostExistsAndLoad(api, driver.MachineName(cc, n))
331+
host, err := machine.LoadHost(api, driver.MachineName(cc, n))
332332
if err != nil {
333333
exit.WithError("Error getting host", err)
334334
}

cmd/minikube/cmd/docker-env.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ var dockerEnvCmd = &cobra.Command{
150150
}
151151
for _, n := range cc.Nodes {
152152
machineName := driver.MachineName(*cc, n)
153-
host, err := machine.CheckIfHostExistsAndLoad(api, machineName)
153+
host, err := machine.LoadHost(api, machineName)
154154
if err != nil {
155155
exit.WithError("Error getting host", err)
156156
}
157157
if host.Driver.DriverName() == driver.None {
158158
exit.UsageT(`'none' driver does not support 'minikube docker-env' command`)
159159
}
160160

161-
hostSt, err := machine.GetHostStatus(api, machineName)
161+
hostSt, err := machine.Status(api, machineName)
162162
if err != nil {
163163
exit.WithError("Error getting host status", err)
164164
}

cmd/minikube/cmd/node_start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var nodeStartCmd = &cobra.Command{
4545
exit.WithError("creating api client", err)
4646
}
4747

48-
if machine.IsHostRunning(api, name) {
48+
if machine.IsRunning(api, name) {
4949
out.T(out.Check, "{{.name}} is already running", out.V{"name": name})
5050
os.Exit(0)
5151
}

cmd/minikube/cmd/pause.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func runPause(cmd *cobra.Command, args []string) {
6666
glog.Infof("config: %+v", cc)
6767

6868
for _, n := range cc.Nodes {
69-
host, err := machine.CheckIfHostExistsAndLoad(api, driver.MachineName(*cc, n))
69+
host, err := machine.LoadHost(api, driver.MachineName(*cc, n))
7070
if err != nil {
7171
exit.WithError("Error getting host", err)
7272
}

cmd/minikube/cmd/podman-env.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ var podmanEnvCmd = &cobra.Command{
121121
}
122122
for _, n := range cc.Nodes {
123123
machineName := driver.MachineName(*cc, n)
124-
host, err := machine.CheckIfHostExistsAndLoad(api, machineName)
124+
host, err := machine.LoadHost(api, machineName)
125125
if err != nil {
126126
exit.WithError("Error getting host", err)
127127
}
128128
if host.Driver.DriverName() == driver.None {
129129
exit.UsageT(`'none' driver does not support 'minikube podman-env' command`)
130130
}
131131

132-
hostSt, err := machine.GetHostStatus(api, machineName)
132+
hostSt, err := machine.Status(api, machineName)
133133
if err != nil {
134134
exit.WithError("Error getting host status", err)
135135
}

cmd/minikube/cmd/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var serviceCmd = &cobra.Command{
9393
exit.WithError("Error getting control plane", err)
9494
}
9595
machineName := driver.MachineName(*cfg, cp)
96-
if !machine.IsHostRunning(api, machineName) {
96+
if !machine.IsRunning(api, machineName) {
9797
os.Exit(1)
9898
}
9999

cmd/minikube/cmd/service_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var serviceListCmd = &cobra.Command{
5656
if err != nil {
5757
exit.WithError("Error getting primary control plane", err)
5858
}
59-
if !machine.IsHostRunning(api, driver.MachineName(*cfg, cp)) {
59+
if !machine.IsRunning(api, driver.MachineName(*cfg, cp)) {
6060
exit.WithCodeT(exit.Unavailable, "profile {{.name}} is not running.", out.V{"name": profileName})
6161
}
6262
serviceURLs, err := service.GetServiceURLs(api, serviceListNamespace, serviceURLTemplate)

cmd/minikube/cmd/ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var sshCmd = &cobra.Command{
5454
if err != nil {
5555
exit.WithError("Error getting primary control plane", err)
5656
}
57-
host, err := machine.CheckIfHostExistsAndLoad(api, driver.MachineName(*cc, cp))
57+
host, err := machine.LoadHost(api, driver.MachineName(*cc, cp))
5858
if err != nil {
5959
exit.WithError("Error getting host", err)
6060
}

cmd/minikube/cmd/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func status(api libmachine.API, name string) (*Status, error) {
157157
Kubeconfig: Nonexistent,
158158
}
159159

160-
hs, err := machine.GetHostStatus(api, name)
160+
hs, err := machine.Status(api, name)
161161
glog.Infof("%s host status = %q (err=%v)", name, hs, err)
162162
if err != nil {
163163
return st, errors.Wrap(err, "host")
@@ -199,7 +199,7 @@ func status(api libmachine.API, name string) (*Status, error) {
199199
st.Kubeconfig = Configured
200200
}
201201

202-
host, err := machine.CheckIfHostExistsAndLoad(api, name)
202+
host, err := machine.LoadHost(api, name)
203203
if err != nil {
204204
return st, err
205205
}

cmd/minikube/cmd/unpause.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var unpauseCmd = &cobra.Command{
5858

5959
for _, n := range cc.Nodes {
6060
machineName := driver.MachineName(*cc, n)
61-
host, err := machine.CheckIfHostExistsAndLoad(api, machineName)
61+
host, err := machine.LoadHost(api, machineName)
6262
if err != nil {
6363
exit.WithError("Error getting host", err)
6464
}

pkg/addons/addons.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func enableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
145145
}
146146

147147
mName := driver.MachineName(*cc, cp)
148-
host, err := machine.CheckIfHostExistsAndLoad(api, mName)
149-
if err != nil || !machine.IsHostRunning(api, mName) {
148+
host, err := machine.LoadHost(api, mName)
149+
if err != nil || !machine.IsRunning(api, mName) {
150150
glog.Warningf("%q is not running, writing %s=%v to disk and skipping enablement (err=%v)", mName, addon.Name(), enable, err)
151151
return nil
152152
}
@@ -247,7 +247,7 @@ func enableOrDisableStorageClasses(cc *config.ClusterConfig, name string, val st
247247
if err != nil {
248248
return errors.Wrap(err, "getting control plane")
249249
}
250-
if !machine.IsHostRunning(api, driver.MachineName(*cc, cp)) {
250+
if !machine.IsRunning(api, driver.MachineName(*cc, cp)) {
251251
glog.Warningf("%q is not running, writing %s=%v to disk and skipping enablement", driver.MachineName(*cc, cp), name, val)
252252
return enableOrDisableAddon(cc, name, val)
253253
}

pkg/drivers/kic/kic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (d *Driver) GetState() (state.State, error) {
226226
}
227227
o := strings.TrimSpace(string(out))
228228
if err != nil {
229-
return state.Error, errors.Wrapf(err, "get container %s status", d.MachineName)
229+
return state.Error, errors.Wrapf(err, "%s: %s", strings.Join(cmd.Args, " "), o)
230230
}
231231
switch o {
232232
case "running":

pkg/minikube/cluster/ip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
7979

8080
// GetHostDriverIP gets the ip address of the current minikube cluster
8181
func GetHostDriverIP(api libmachine.API, machineName string) (net.IP, error) {
82-
host, err := machine.CheckIfHostExistsAndLoad(api, machineName)
82+
host, err := machine.LoadHost(api, machineName)
8383
if err != nil {
8484
return nil, err
8585
}

pkg/minikube/machine/cache_images.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func CacheAndLoadImages(images []string) error {
152152
}
153153
for _, n := range c.Nodes {
154154
m := driver.MachineName(*c, n)
155-
status, err := GetHostStatus(api, m)
155+
status, err := Status(api, m)
156156
if err != nil {
157157
glog.Warningf("skipping loading cache for profile %s", pName)
158158
glog.Errorf("error getting status for %s: %v", pName, err)

pkg/minikube/machine/cluster_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func TestDeleteHostErrMachineNotExist(t *testing.T) {
374374
}
375375
}
376376

377-
func TestGetHostStatus(t *testing.T) {
377+
func TestStatus(t *testing.T) {
378378
RegisterMockDriver(t)
379379
api := tests.NewMockAPI(t)
380380

@@ -384,7 +384,7 @@ func TestGetHostStatus(t *testing.T) {
384384
m := driver.MachineName(cc, config.Node{Name: "minikube"})
385385

386386
checkState := func(expected string, machineName string) {
387-
s, err := GetHostStatus(api, machineName)
387+
s, err := Status(api, machineName)
388388
if err != nil {
389389
t.Fatalf("Unexpected error getting status: %v", err)
390390
}

pkg/minikube/machine/delete.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func DeleteHost(api libmachine.API, machineName string) error {
6464
}
6565

6666
// Get the status of the host. Ensure that it exists before proceeding ahead.
67-
status, err := GetHostStatus(api, machineName)
67+
status, err := Status(api, machineName)
6868
if err != nil {
6969
// Warn, but proceed
70-
out.WarningT("Unable to get the status of the {{.name}} cluster.", out.V{"name": machineName})
70+
out.WarningT(`Unable to get host status for "{{.name}}": {{.error}}`, out.V{"name": machineName, "error": err})
7171
}
7272

7373
if status == state.None.String() {

pkg/minikube/machine/status.go renamed to pkg/minikube/machine/host.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/pkg/errors"
2525
)
2626

27-
// GetHostStatus gets the status of the host VM.
28-
func GetHostStatus(api libmachine.API, machineName string) (string, error) {
27+
// Status returns the status of a libmachine host
28+
func Status(api libmachine.API, machineName string) (string, error) {
2929
exists, err := api.Exists(machineName)
3030
if err != nil {
3131
return "", errors.Wrapf(err, "%s exists", machineName)
@@ -46,9 +46,9 @@ func GetHostStatus(api libmachine.API, machineName string) (string, error) {
4646
return s.String(), nil
4747
}
4848

49-
// IsHostRunning asserts that this profile's primary host is in state "Running"
50-
func IsHostRunning(api libmachine.API, name string) bool {
51-
s, err := GetHostStatus(api, name)
49+
// IsRunning asserts that a libmachine host is in state "Running"
50+
func IsRunning(api libmachine.API, name string) bool {
51+
s, err := Status(api, name)
5252
if err != nil {
5353
glog.Warningf("host status for %q returned error: %v", name, err)
5454
return false
@@ -60,8 +60,8 @@ func IsHostRunning(api libmachine.API, name string) bool {
6060
return true
6161
}
6262

63-
// CheckIfHostExistsAndLoad checks if a host exists, and loads it if it does
64-
func CheckIfHostExistsAndLoad(api libmachine.API, machineName string) (*host.Host, error) {
63+
// LoadHost returns a libmachine host by name
64+
func LoadHost(api libmachine.API, machineName string) (*host.Host, error) {
6565
glog.Infof("Checking if %q exists ...", machineName)
6666
exists, err := api.Exists(machineName)
6767
if err != nil {
@@ -71,9 +71,9 @@ func CheckIfHostExistsAndLoad(api libmachine.API, machineName string) (*host.Hos
7171
return nil, errors.Errorf("machine %q does not exist", machineName)
7272
}
7373

74-
host, err := api.Load(machineName)
74+
h, err := api.Load(machineName)
7575
if err != nil {
7676
return nil, errors.Wrapf(err, "loading machine %q", machineName)
7777
}
78-
return host, nil
78+
return h, nil
7979
}

pkg/minikube/machine/machine.go

+3-56
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ import (
2020
"io/ioutil"
2121
"path/filepath"
2222

23-
"github.com/docker/machine/libmachine"
2423
"github.com/docker/machine/libmachine/host"
25-
"github.com/docker/machine/libmachine/state"
26-
"github.com/golang/glog"
2724
"github.com/pkg/errors"
28-
"k8s.io/minikube/pkg/minikube/config"
29-
"k8s.io/minikube/pkg/minikube/driver"
3025
"k8s.io/minikube/pkg/minikube/localpath"
3126
)
3227

@@ -63,37 +58,14 @@ func (h *Machine) IsValid() bool {
6358
return true
6459
}
6560

66-
// List return all valid and invalid machines
67-
// If a machine is valid or invalid is determined by the cluster.IsValid function
68-
func List(miniHome ...string) (validMachines []*Machine, inValidMachines []*Machine, err error) {
69-
pDirs, err := machineDirs(miniHome...)
70-
if err != nil {
71-
return nil, nil, err
72-
}
73-
for _, n := range pDirs {
74-
p, err := Load(n)
75-
if err != nil {
76-
glog.Infof("%s not valid: %v", n, err)
77-
inValidMachines = append(inValidMachines, p)
78-
continue
79-
}
80-
if !p.IsValid() {
81-
inValidMachines = append(inValidMachines, p)
82-
continue
83-
}
84-
validMachines = append(validMachines, p)
85-
}
86-
return validMachines, inValidMachines, nil
87-
}
88-
89-
// Load loads a machine or throws an error if the machine could not be loaded.
90-
func Load(name string) (*Machine, error) {
61+
// LoadMachine returns a Machine abstracting a libmachine.Host
62+
func LoadMachine(name string) (*Machine, error) {
9163
api, err := NewAPIClient()
9264
if err != nil {
9365
return nil, err
9466
}
9567

96-
h, err := CheckIfHostExistsAndLoad(api, name)
68+
h, err := LoadHost(api, name)
9769
if err != nil {
9870
return nil, err
9971
}
@@ -104,7 +76,6 @@ func Load(name string) (*Machine, error) {
10476
} else {
10577
return nil, errors.New("host is nil")
10678
}
107-
10879
return &mm, nil
10980
}
11081

@@ -122,27 +93,3 @@ func machineDirs(miniHome ...string) (dirs []string, err error) {
12293
}
12394
return dirs, err
12495
}
125-
126-
// CreateSSHShell creates a new SSH shell / client
127-
func CreateSSHShell(api libmachine.API, cc config.ClusterConfig, n config.Node, args []string) error {
128-
machineName := driver.MachineName(cc, n)
129-
host, err := CheckIfHostExistsAndLoad(api, machineName)
130-
if err != nil {
131-
return errors.Wrap(err, "host exists and load")
132-
}
133-
134-
currentState, err := host.Driver.GetState()
135-
if err != nil {
136-
return errors.Wrap(err, "state")
137-
}
138-
139-
if currentState != state.Running {
140-
return errors.Errorf("%q is not running", machineName)
141-
}
142-
143-
client, err := host.CreateSSHClient()
144-
if err != nil {
145-
return errors.Wrap(err, "Creating ssh client")
146-
}
147-
return client.Shell(args...)
148-
}

0 commit comments

Comments
 (0)