Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete docker volumes when deleting a single node #8224

Merged
merged 4 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}

}