Skip to content

Commit

Permalink
Merge pull request #5916 from tstromberg/recover-ctrlc
Browse files Browse the repository at this point in the history
Make it possible to recover from a previously aborted StartCluster (Ctrl-C)
  • Loading branch information
tstromberg authored Nov 15, 2019
2 parents 6faa8fc + 2223c89 commit 6c44e09
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
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 @@ -221,8 +229,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 @@ -243,6 +263,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 @@ -280,6 +301,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 @@ -450,12 +472,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 @@ -528,7 +551,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

0 comments on commit 6c44e09

Please sign in to comment.