Unverified Commit 70e5d3cf authored by Sharif Elgamal's avatar Sharif Elgamal Committed by GitHub

Merge pull request #8224 from sharifelgamal/node-delete-vol

delete docker volumes when deleting a single node
parents 07c7b7ca 6cd09ffa
Pipeline #148136977 passed with stage
in 3 minutes and 9 seconds
......@@ -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})
},
}
......
......@@ -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
......
......@@ -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())
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment