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

add delete-on-failure flag #7345

Merged
merged 5 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const (
natNicType = "nat-nic-type"
nodes = "nodes"
preload = "preload"
deleteOnFailure = "delete-on-failure"
)

var (
Expand Down Expand Up @@ -177,6 +178,7 @@ func initMinikubeFlags() {
startCmd.Flags().Bool(installAddons, true, "If set, install addons. Defaults to true.")
startCmd.Flags().IntP(nodes, "n", 1, "The number of nodes to spin up. Defaults to 1.")
startCmd.Flags().Bool(preload, true, "If set, download tarball of preloaded images if available to improve start time. Defaults to true.")
startCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again.")
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
}

// initKubernetesFlags inits the commandline flags for kubernetes related options
Expand Down Expand Up @@ -353,7 +355,27 @@ func runStart(cmd *cobra.Command, args []string) {
}
}

kubeconfig := node.Start(cc, n, existingAddons, true)
kubeconfig, err := node.Start(cc, n, existingAddons, true)
if err != nil && viper.GetBool(deleteOnFailure) {
out.T(out.Warning, "Cluster {{.name}} failed to start, deleting and trying again.", out.V{"name": cc.Name})
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
// Start failed, delete the cluster and try again
profile, err := config.LoadProfile(cc.Name)
if err != nil {
out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": cc.Name})
}

err = deleteProfile(profile)
if err != nil {
// We failed to delete? That's not good. Error out.
exit.WithError("deleting cluster failed", err)
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
}

kubeconfig, err = node.Start(cc, n, existingAddons, true)
if err != nil {
// Ok we failed again, let's bail
exit.WithError("Start failed after cluster deletion", err)
}
}

numNodes := viper.GetInt(nodes)
if numNodes == 1 && existing != nil {
Expand Down
26 changes: 13 additions & 13 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (
)

// Start spins up a guest and starts the kubernetes node.
func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]bool, apiServer bool) *kubeconfig.Settings {
func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]bool, apiServer bool) (*kubeconfig.Settings, error) {
cp := ""
if apiServer {
cp = "control plane "
Expand Down Expand Up @@ -100,7 +100,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo

sv, err := util.ParseKubernetesVersion(n.KubernetesVersion)
if err != nil {
exit.WithError("Failed to parse kubernetes version", err)
return nil, errors.Wrap(err, "Failed to parse kubernetes version")
}

// configure the runtime (docker, containerd, crio)
Expand All @@ -113,7 +113,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
// Must be written before bootstrap, otherwise health checks may flake due to stale IP
kcs = setupKubeconfig(host, &cc, &n, cc.Name)
if err != nil {
exit.WithError("Failed to setup kubeconfig", err)
return nil, errors.Wrap(err, "Failed to setup kubeconfig")
}

// setup kubeadm (must come after setupKubeconfig)
Expand All @@ -125,16 +125,16 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo

// write the kubeconfig to the file system after everything required (like certs) are created by the bootstrapper
if err := kubeconfig.Update(kcs); err != nil {
exit.WithError("Failed to update kubeconfig file.", err)
return nil, errors.Wrap(err, "Failed to update kubeconfig file.")
}
} else {
bs, err = cluster.Bootstrapper(machineAPI, viper.GetString(cmdcfg.Bootstrapper), cc, n)
if err != nil {
exit.WithError("Failed to get bootstrapper", err)
return nil, errors.Wrap(err, "Failed to get bootstrapper")
}

if err = bs.SetupCerts(cc.KubernetesConfig, n); err != nil {
exit.WithError("setting up certs", err)
return nil, errors.Wrap(err, "setting up certs")
}
}

Expand All @@ -159,34 +159,34 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
// Skip pre-existing, because we already waited for health
if viper.GetBool(waitUntilHealthy) && !preExists {
if err := bs.WaitForNode(cc, n, viper.GetDuration(waitTimeout)); err != nil {
exit.WithError("Wait failed", err)
return nil, errors.Wrap(err, "Wait failed")
}
}
} else {
if err := bs.UpdateNode(cc, n, cr); err != nil {
exit.WithError("Updating node", err)
return nil, errors.Wrap(err, "Updating node")
}

cp, err := config.PrimaryControlPlane(&cc)
if err != nil {
exit.WithError("Getting primary control plane", err)
return nil, errors.Wrap(err, "Getting primary control plane")
}
cpBs, err := cluster.Bootstrapper(machineAPI, viper.GetString(cmdcfg.Bootstrapper), cc, cp)
if err != nil {
exit.WithError("Getting bootstrapper", err)
return nil, errors.Wrap(err, "Getting bootstrapper")
}

joinCmd, err := cpBs.GenerateToken(cc)
if err != nil {
exit.WithError("generating join token", err)
return nil, errors.Wrap(err, "generating join token")
}

if err = bs.JoinCluster(cc, n, joinCmd); err != nil {
exit.WithError("joining cluster", err)
return nil, errors.Wrap(err, "joining cluster")
}
}

return kcs
return kcs, nil
}

// ConfigureRuntimes does what needs to happen to get a runtime going.
Expand Down