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

Make it possible to recover from a previously aborted StartCluster (Ctrl-C) #5916

Merged
merged 5 commits into from
Nov 15, 2019
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
11 changes: 0 additions & 11 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,24 +1210,13 @@ func configureRuntimes(runner cruntime.CommandRunner, drvName string, k8s cfg.Ku

// bootstrapCluster starts Kubernetes using the chosen bootstrapper
func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner command.Runner, kc cfg.KubernetesConfig, preexisting bool, isUpgrade bool) {
// hum. bootstrapper.Bootstrapper should probably have a Name function.
bsName := viper.GetString(cmdcfg.Bootstrapper)

if isUpgrade || !preexisting {
out.T(out.Pulling, "Pulling images ...")
if err := bs.PullImages(kc); err != nil {
out.T(out.FailureType, "Unable to pull images, which may be OK: {{.error}}", out.V{"error": err})
}
}

if preexisting {
out.T(out.Restarting, "Relaunching Kubernetes using {{.bootstrapper}} ... ", out.V{"bootstrapper": bsName})
if err := bs.RestartCluster(kc); err != nil {
exit.WithLogEntries("Error restarting cluster", err, logs.FindProblems(r, bs, runner))
}
return
}

out.T(out.Launch, "Launching Kubernetes ... ")
if err := bs.StartCluster(kc); err != nil {
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(r, bs, runner))
Expand Down
1 change: 0 additions & 1 deletion pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Bootstrapper interface {
PullImages(config.KubernetesConfig) error
StartCluster(config.KubernetesConfig) error
UpdateCluster(config.KubernetesConfig) error
RestartCluster(config.KubernetesConfig) error
DeleteCluster(config.KubernetesConfig) error
WaitForCluster(config.KubernetesConfig, time.Duration) error
// LogCommands returns a map of log type to a command which will display that log.
Expand Down
33 changes: 28 additions & 5 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ var KubeadmExtraArgsWhitelist = map[int][]string{
},
}

// remote artifacts that must exist for minikube to function properly. The sign of a previously working installation.
// NOTE: /etc is not persistent across restarts, so don't bother checking there
var expectedArtifacts = []string{
"/var/lib/kubelet/kubeadm-flags.env",
"/var/lib/kubelet/config.yaml",
etcdDataDir(),
}

// yamlConfigPath is the path to the kubeadm configuration
var yamlConfigPath = path.Join(vmpath.GuestEphemeralDir, "kubeadm.yaml")

Expand Down Expand Up @@ -222,8 +230,20 @@ func (k *Bootstrapper) createCompatSymlinks() error {
return nil
}

func (k *Bootstrapper) existingConfig() error {
args := append([]string{"ls"}, expectedArtifacts...)
_, err := k.c.RunCmd(exec.Command("sudo", args...))
return err
}

// StartCluster starts the cluster
func (k *Bootstrapper) StartCluster(k8s config.KubernetesConfig) error {
err := k.existingConfig()
if err == nil {
return k.restartCluster(k8s)
}
glog.Infof("existence check: %v", err)

start := time.Now()
glog.Infof("StartCluster: %+v", k8s)
defer func() {
Expand All @@ -244,6 +264,7 @@ func (k *Bootstrapper) StartCluster(k8s config.KubernetesConfig) error {
ignore := []string{
fmt.Sprintf("DirAvailable-%s", strings.Replace(vmpath.GuestManifestsDir, "/", "-", -1)),
fmt.Sprintf("DirAvailable-%s", strings.Replace(vmpath.GuestPersistentDir, "/", "-", -1)),
fmt.Sprintf("DirAvailable-%s", strings.Replace(etcdDataDir(), "/", "-", -1)),
"FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml",
"FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml",
"FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml",
Expand Down Expand Up @@ -281,6 +302,7 @@ func (k *Bootstrapper) StartCluster(k8s config.KubernetesConfig) error {
if err := k.adjustResourceLimits(); err != nil {
glog.Warningf("unable to adjust resource limits: %v", err)
}

return nil
}

Expand Down Expand Up @@ -451,12 +473,13 @@ func (k *Bootstrapper) WaitForCluster(k8s config.KubernetesConfig, timeout time.
return k.waitForSystemPods(start, k8s, timeout)
}

// RestartCluster restarts the Kubernetes cluster configured by kubeadm
func (k *Bootstrapper) RestartCluster(k8s config.KubernetesConfig) error {
glog.Infof("RestartCluster start")
// restartCluster restarts the Kubernetes cluster configured by kubeadm
func (k *Bootstrapper) restartCluster(k8s config.KubernetesConfig) error {
glog.Infof("restartCluster start")

start := time.Now()
defer func() {
glog.Infof("RestartCluster took %s", time.Since(start))
glog.Infof("restartCluster took %s", time.Since(start))
}()

version, err := parseKubernetesVersion(k8s.KubernetesVersion)
Expand Down Expand Up @@ -529,7 +552,7 @@ func (k *Bootstrapper) DeleteCluster(k8s config.KubernetesConfig) error {
return nil
}

// PullImages downloads images that will be used by RestartCluster
// PullImages downloads images that will be used by Kubernetes
func (k *Bootstrapper) PullImages(k8s config.KubernetesConfig) error {
version, err := parseKubernetesVersion(k8s.KubernetesVersion)
if err != nil {
Expand Down