提交 84eea2f4 编写于 作者: S Sharif Elgamal

recreate hosts on failed provisioning if delete-on-failure is specified

上级 f480dc4f
......@@ -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)
......
......@@ -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"
......@@ -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)
}
......
......@@ -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
}
......@@ -306,7 +306,7 @@ 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")
}
......@@ -314,7 +314,7 @@ func startWithDriver(starter node.Starter, existing *config.ClusterConfig) (*kub
} 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")
}
......@@ -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,
......
......@@ -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
}
......
......@@ -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 {
......@@ -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)
}
......@@ -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")
}
......@@ -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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册