Skip to content

Commit

Permalink
Merge pull request #8224 from sharifelgamal/node-delete-vol
Browse files Browse the repository at this point in the history
delete docker volumes when deleting a single node
  • Loading branch information
sharifelgamal authored May 20, 2020
2 parents 07c7b7c + 6cd09ff commit 70e5d3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 8 additions & 1 deletion cmd/minikube/cmd/node_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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})
},
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/minikube/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/integration/multinode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package integration

import (
"context"
"fmt"
"os/exec"
"strings"
"testing"
Expand Down Expand Up @@ -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())
}
}

}

0 comments on commit 70e5d3c

Please sign in to comment.