Skip to content

Commit

Permalink
Update kubeadm restart commands to support v1.13.x (#3483)
Browse files Browse the repository at this point in the history
* Minor changes for compatibility with v1.13.1

* etcd subcommand should be local instead of all
  • Loading branch information
tstromberg authored and balopat committed Dec 21, 2018
1 parent ab64cb9 commit f6af1ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
28 changes: 19 additions & 9 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,31 @@ func addAddons(files *[]assets.CopyableFile) error {
}

func (k *KubeadmBootstrapper) RestartCluster(k8s config.KubernetesConfig) error {
opts := struct {
KubeadmConfigFile string
}{
KubeadmConfigFile: constants.KubeadmConfigFile,
version, err := ParseKubernetesVersion(k8s.KubernetesVersion)
if err != nil {
return errors.Wrap(err, "parsing kubernetes version")
}

b := bytes.Buffer{}
if err := kubeadmRestoreTemplate.Execute(&b, opts); err != nil {
return err
phase := "alpha"
controlPlane := "controlplane"
if version.GTE(semver.MustParse("1.13.0")) {
phase = "init"
controlPlane = "control-plane"
}

if err := k.c.Run(b.String()); err != nil {
return errors.Wrapf(err, "running cmd: %s", b.String())
cmds := []string{
fmt.Sprintf("sudo kubeadm %s phase certs all --config %s", phase, constants.KubeadmConfigFile),
fmt.Sprintf("sudo kubeadm %s phase kubeconfig all --config %s", phase, constants.KubeadmConfigFile),
fmt.Sprintf("sudo kubeadm %s phase %s all --config %s", phase, controlPlane, constants.KubeadmConfigFile),
fmt.Sprintf("sudo kubeadm %s phase etcd local --config %s", phase, constants.KubeadmConfigFile),
}

// Run commands one at a time so that it is easier to root cause failures.
for _, cmd := range cmds {
if err := k.c.Run(cmd); err != nil {
return errors.Wrapf(err, "running cmd: %s", cmd)
}
}
if err := restartKubeProxy(k8s); err != nil {
return errors.Wrap(err, "restarting kube-proxy")
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/minikube/bootstrapper/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ RestartSec=10
WantedBy=multi-user.target
`

var kubeadmRestoreTemplate = template.Must(template.New("kubeadmRestoreTemplate").Parse(`
sudo kubeadm alpha phase certs all --config {{.KubeadmConfigFile}} &&
sudo /usr/bin/kubeadm alpha phase kubeconfig all --config {{.KubeadmConfigFile}} &&
sudo /usr/bin/kubeadm alpha phase controlplane all --config {{.KubeadmConfigFile}} &&
sudo /usr/bin/kubeadm alpha phase etcd local --config {{.KubeadmConfigFile}}
`))

var kubeadmInitTemplate = template.Must(template.New("kubeadmInitTemplate").Parse(`
sudo /usr/bin/kubeadm init --config {{.KubeadmConfigFile}} {{if .SkipPreflightChecks}}--skip-preflight-checks{{else}}{{range .Preflights}}--ignore-preflight-errors={{.}} {{end}}{{end}}
`))
Expand Down

0 comments on commit f6af1ce

Please sign in to comment.