Skip to content

Commit

Permalink
Merge pull request #65802 from xlgao-zju/improve-output
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

[kubeadm] Print required flags when running kubeadm upgrade plan

**What this PR does / why we need it**:
print required flags when running kubeadm upgrade plan

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Close [kubernetes/kubeadm#935](kubernetes/kubeadm#935)

**Special notes for your reviewer**:
/assign @chuckha 
/assign @neolit123 

**Release note**:

```release-note
kubeadm: print required flags when running kubeadm upgrade plan
```
  • Loading branch information
Kubernetes Submit Queue committed Jul 7, 2018
2 parents 097f300 + 0055276 commit 2d288a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"
"sort"
"strings"
"text/tabwriter"

"github.com/golang/glog"
Expand All @@ -33,6 +34,7 @@ import (
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
etcdutil "k8s.io/kubernetes/cmd/kubeadm/app/util/etcd"
"k8s.io/kubernetes/pkg/util/version"
)

type planFlags struct {
Expand Down Expand Up @@ -147,6 +149,21 @@ func printAvailableUpgrades(upgrades []upgrade.Upgrade, w io.Writer, isExternalE
// Loop through the upgrade possibilities and output text to the command line
for _, upgrade := range upgrades {

newK8sVersion, err := version.ParseSemantic(upgrade.After.KubeVersion)
if err != nil {
fmt.Fprintf(w, "Unable to parse normalized version %q as a semantic version\n", upgrade.After.KubeVersion)
continue
}

UnstableVersionFlag := ""
if len(newK8sVersion.PreRelease()) != 0 {
if strings.HasPrefix(newK8sVersion.PreRelease(), "rc") {
UnstableVersionFlag = " --allow-release-candidate-upgrades"
} else {
UnstableVersionFlag = " --allow-experimental-upgrades"
}
}

if isExternalEtcd && upgrade.CanUpgradeEtcd() {
fmt.Fprintln(w, "External components that should be upgraded manually before you upgrade the control plane with 'kubeadm upgrade apply':")
fmt.Fprintln(tabw, "COMPONENT\tCURRENT\tAVAILABLE")
Expand Down Expand Up @@ -226,7 +243,7 @@ func printAvailableUpgrades(upgrades []upgrade.Upgrade, w io.Writer, isExternalE
fmt.Fprintln(w, "")
fmt.Fprintln(w, "You can now apply the upgrade by executing the following command:")
fmt.Fprintln(w, "")
fmt.Fprintf(w, "\tkubeadm upgrade apply %s\n", upgrade.After.KubeVersion)
fmt.Fprintf(w, "\tkubeadm upgrade apply %s%s\n", upgrade.After.KubeVersion, UnstableVersionFlag)
fmt.Fprintln(w, "")

if upgrade.Before.KubeadmVersion != upgrade.After.KubeadmVersion {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/cmd/upgrade/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Etcd 3.0.17 3.1.12
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.9.0-beta.1
kubeadm upgrade apply v1.9.0-beta.1 --allow-experimental-upgrades
Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.0-beta.1.
Expand Down Expand Up @@ -350,7 +350,7 @@ Etcd 3.0.17 3.1.12
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.9.0-rc.1
kubeadm upgrade apply v1.9.0-rc.1 --allow-release-candidate-upgrades
Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.0-rc.1.
Expand Down

0 comments on commit 2d288a7

Please sign in to comment.