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-on-faliure recreates clusterย for kubeadm failures as well #16890

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
32 changes: 24 additions & 8 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ func handleAPIServer(starter Starter, cr cruntime.Manager, hostIP net.IP) (*kube
}

// Setup kubeadm (must come after setupKubeconfig).
bs := setupKubeAdm(starter.MachineAPI, *starter.Cfg, *starter.Node, starter.Runner)
bs, err := setupKubeAdm(starter.MachineAPI, *starter.Cfg, *starter.Node, starter.Runner)
if err != nil {
return nil, nil, errors.Wrap(err, "Failed to setup kubeadm")
}
err = bs.StartCluster(*starter.Cfg)
if err != nil {
ExitIfFatal(err, false)
Expand Down Expand Up @@ -554,10 +557,15 @@ func waitForCRIVersion(runner cruntime.CommandRunner, socket string, wait int, i
}

// setupKubeAdm adds any requested files into the VM before Kubernetes is started
func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node, r command.Runner) bootstrapper.Bootstrapper {
func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node, r command.Runner) (bootstrapper.Bootstrapper, error) {
deleteOnFailure := viper.GetBool("delete-on-failure")
bs, err := cluster.Bootstrapper(mAPI, viper.GetString(cmdcfg.Bootstrapper), cfg, r)
if err != nil {
exit.Error(reason.InternalBootstrapper, "Failed to get bootstrapper", err)
klog.Errorf("Failed to get bootstrapper: %v", err)
if !deleteOnFailure {
exit.Error(reason.InternalBootstrapper, "Failed to get bootstrapper", err)
}
return nil, err
}
for _, eo := range cfg.KubernetesConfig.ExtraOptions {
out.Infof("{{.extra_option_component_name}}.{{.key}}={{.value}}", out.V{"extra_option_component_name": eo.Component, "key": eo.Key, "value": eo.Value})
Expand All @@ -566,17 +574,25 @@ func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node,
// update cluster and set up certs

if err := bs.UpdateCluster(cfg); err != nil {
if errors.Is(err, cruntime.ErrContainerRuntimeNotRunning) {
exit.Error(reason.KubernetesInstallFailedRuntimeNotRunning, "Failed to update cluster", err)
if !deleteOnFailure {
if errors.Is(err, cruntime.ErrContainerRuntimeNotRunning) {
exit.Error(reason.KubernetesInstallFailedRuntimeNotRunning, "Failed to update cluster", err)
}
exit.Error(reason.KubernetesInstallFailed, "Failed to update cluster", err)
}
exit.Error(reason.KubernetesInstallFailed, "Failed to update cluster", err)
klog.Errorf("Failed to update cluster: %v", err)
return nil, err
}

if err := bs.SetupCerts(cfg, n); err != nil {
exit.Error(reason.GuestCert, "Failed to setup certs", err)
if !deleteOnFailure {
exit.Error(reason.GuestCert, "Failed to setup certs", err)
}
klog.Errorf("Failed to setup certs: %v", err)
return nil, err
}

return bs
return bs, nil
}

func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clusterName string) *kubeconfig.Settings {
Expand Down