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

ensure deleting failed hosts if --delete-on-failure is specified #8628

Merged
merged 1 commit into from
Jul 1, 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
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/node_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var nodeAddCmd = &cobra.Command{
}
}

if err := node.Add(cc, n); err != nil {
if err := node.Add(cc, n, false); err != nil {
_, err := maybeDeleteAndRetry(*cc, n, nil, err)
if err != nil {
exit.WithError("failed to add node", err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/minikube/cmd/node_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
Expand Down Expand Up @@ -51,7 +52,7 @@ var nodeStartCmd = &cobra.Command{
os.Exit(0)
}

r, p, m, h, err := node.Provision(cc, n, false)
r, p, m, h, err := node.Provision(cc, n, false, viper.GetBool(deleteOnFailure))
if err != nil {
exit.WithError("provisioning host for node", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
}
}

mRunner, preExists, mAPI, host, err := node.Provision(&cc, &n, true)
mRunner, preExists, mAPI, host, err := node.Provision(&cc, &n, true, viper.GetBool(deleteOnFailure))
if err != nil {
return node.Starter{}, err
}
Expand Down Expand Up @@ -306,15 +306,15 @@ func startWithDriver(starter node.Starter, existing *config.ClusterConfig) (*kub
KubernetesVersion: starter.Cfg.KubernetesConfig.KubernetesVersion,
}
out.Ln("") // extra newline for clarity on the command line
err := node.Add(starter.Cfg, n)
err := node.Add(starter.Cfg, n, viper.GetBool(deleteOnFailure))
if err != nil {
return nil, errors.Wrap(err, "adding node")
}
}
} else {
for _, n := range existing.Nodes {
if !n.ControlPlane {
err := node.Add(starter.Cfg, n)
err := node.Add(starter.Cfg, n, viper.GetBool(deleteOnFailure))
if err != nil {
return nil, errors.Wrap(err, "adding node")
}
Expand Down Expand Up @@ -417,7 +417,7 @@ func maybeDeleteAndRetry(cc config.ClusterConfig, n config.Node, existingAddons

var kubeconfig *kubeconfig.Settings
for _, n := range cc.Nodes {
r, p, m, h, err := node.Provision(&cc, &n, n.ControlPlane)
r, p, m, h, err := node.Provision(&cc, &n, n.ControlPlane, false)
s := node.Starter{
Runner: r,
PreExists: p,
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const (
)

// Add adds a new node config to an existing cluster.
func Add(cc *config.ClusterConfig, n config.Node) error {
func Add(cc *config.ClusterConfig, n config.Node, delOnFail bool) error {
if err := config.SaveNode(cc, &n); err != nil {
return errors.Wrap(err, "save node")
}

r, p, m, h, err := Provision(cc, &n, false)
r, p, m, h, err := Provision(cc, &n, false, delOnFail)
if err != nil {
return err
}
Expand Down
19 changes: 14 additions & 5 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
}

// Provision provisions the machine/container for the node
func Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool) (command.Runner, bool, libmachine.API, *host.Host, error) {
func Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool, delOnFail bool) (command.Runner, bool, libmachine.API, *host.Host, error) {

name := driver.MachineName(*cc, *n)
if apiServer {
Expand All @@ -230,7 +230,7 @@ func Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool) (comman
handleDownloadOnly(&cacheGroup, &kicGroup, n.KubernetesVersion)
waitDownloadKicBaseImage(&kicGroup)

return startMachine(cc, n)
return startMachine(cc, n, delOnFail)

}

Expand Down Expand Up @@ -336,12 +336,12 @@ func apiServerURL(h host.Host, cc config.ClusterConfig, n config.Node) (string,
}

// StartMachine starts a VM
func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.Runner, preExists bool, machineAPI libmachine.API, host *host.Host, err error) {
func startMachine(cfg *config.ClusterConfig, node *config.Node, delOnFail bool) (runner command.Runner, preExists bool, machineAPI libmachine.API, host *host.Host, err error) {
m, err := machine.NewAPIClient()
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to get machine client")
}
host, preExists, err = startHost(m, cfg, node)
host, preExists, err = startHost(m, cfg, node, delOnFail)
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to start host")
}
Expand All @@ -365,7 +365,7 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.
}

// startHost starts a new minikube host using a VM or None
func startHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*host.Host, bool, error) {
func startHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node, delOnFail bool) (*host.Host, bool, error) {
host, exists, err := machine.StartHost(api, cc, n)
if err == nil {
return host, exists, nil
Expand All @@ -388,6 +388,15 @@ func startHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*h
// Try again, but just once to avoid making the logs overly confusing
time.Sleep(5 * time.Second)

if delOnFail {
glog.Info("Deleting existing host since delete-on-failure was set.")
// Delete the failed existing host
err := machine.DeleteHost(api, driver.MachineName(*cc, *n))
if err != nil {
glog.Warningf("delete host: %v", err)
}
}

host, exists, err = machine.StartHost(api, cc, n)
if err == nil {
return host, exists, nil
Expand Down