diff --git a/cmd/minikube/cmd/node_delete.go b/cmd/minikube/cmd/node_delete.go index bca5c497c4e2..634ac92b8cf9 100644 --- a/cmd/minikube/cmd/node_delete.go +++ b/cmd/minikube/cmd/node_delete.go @@ -18,6 +18,7 @@ package cmd import ( "github.com/spf13/cobra" + "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/mustload" "k8s.io/minikube/pkg/minikube/node" @@ -38,10 +39,16 @@ var nodeDeleteCmd = &cobra.Command{ co := mustload.Healthy(ClusterFlagValue()) out.T(out.DeletingHost, "Deleting node {{.name}} from cluster {{.cluster}}", out.V{"name": name, "cluster": co.Config.Name}) - if err := node.Delete(*co.Config, name); err != nil { + n, err := node.Delete(*co.Config, name) + if err != nil { exit.WithError("deleting node", err) } + if driver.IsKIC(co.Config.Driver) { + machineName := driver.MachineName(*co.Config, *n) + deletePossibleKicLeftOver(machineName, co.Config.Driver) + } + out.T(out.Deleted, "Node {{.name}} was successfully deleted.", out.V{"name": name}) }, } diff --git a/pkg/minikube/node/node.go b/pkg/minikube/node/node.go index dcc4f4d7d536..74cb8f69d7ec 100644 --- a/pkg/minikube/node/node.go +++ b/pkg/minikube/node/node.go @@ -58,24 +58,24 @@ func Add(cc *config.ClusterConfig, n config.Node) error { } // Delete stops and deletes the given node from the given cluster -func Delete(cc config.ClusterConfig, name string) error { +func Delete(cc config.ClusterConfig, name string) (*config.Node, error) { n, index, err := Retrieve(&cc, name) if err != nil { - return errors.Wrap(err, "retrieve") + return n, errors.Wrap(err, "retrieve") } api, err := machine.NewAPIClient() if err != nil { - return err + return n, err } err = machine.DeleteHost(api, driver.MachineName(cc, *n)) if err != nil { - return err + return n, err } cc.Nodes = append(cc.Nodes[:index], cc.Nodes[index+1:]...) - return config.SaveProfile(viper.GetString(config.ProfileName), &cc) + return n, config.SaveProfile(viper.GetString(config.ProfileName), &cc) } // Retrieve finds the node by name in the given cluster diff --git a/test/integration/multinode_test.go b/test/integration/multinode_test.go index a69f86a43b6d..8ddf42b5f03d 100644 --- a/test/integration/multinode_test.go +++ b/test/integration/multinode_test.go @@ -20,6 +20,7 @@ package integration import ( "context" + "fmt" "os/exec" "strings" "testing" @@ -189,4 +190,14 @@ func validateDeleteNodeFromMultiNode(ctx context.Context, t *testing.T, profile t.Errorf("status says both kubelets are not running: args %q: %v", rr.Command(), rr.Stdout.String()) } + if DockerDriver() { + rr, err := Run(t, exec.Command("docker", "volume", "ls")) + if err != nil { + t.Errorf("failed to run %q : %v", rr.Command(), err) + } + if strings.Contains(rr.Stdout.String(), fmt.Sprintf("%s-%s", profile, name)) { + t.Errorf("docker volume was not properly deleted: %s", rr.Stdout.String()) + } + } + }