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

Changes kubeadm upgrade plan output & strategy #63016

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 22 additions & 23 deletions cmd/kubeadm/app/cmd/upgrade/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,32 @@ func printAvailableUpgrades(upgrades []upgrade.Upgrade, w io.Writer, featureGate
fmt.Fprintln(w, "")
}

fmt.Fprintf(w, "Upgrade to the latest %s:\n", upgrade.Description)
fmt.Fprintln(w, "")
fmt.Fprintln(tabw, "COMPONENT\tCURRENT\tAVAILABLE")
fmt.Fprintf(tabw, "API Server\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Controller Manager\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Scheduler\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Kube Proxy\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
if features.Enabled(featureGates, features.CoreDNS) {
fmt.Fprintf(tabw, "CoreDNS\t%s\t%s\n", upgrade.Before.DNSVersion, upgrade.After.DNSVersion)
if upgrade.Before.KubeadmVersion != upgrade.After.KubeadmVersion {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upgrade guides for 1.7->1.8 and 1.8->1.9 both recommend to use the latest stable version of kubeadm for upgrades, i.e. not just the exact version you’d want to upgrade to. With that in mind this check doesn’t make sense; I would expect it to check if the kubeadm version is the same or newer.

#62568 already ensures that the major and minor versions are the same.

Copy link
Contributor Author

@chuckha chuckha Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feedback, thanks.

I'll need to resolve #62568 with what I'm trying to accomplish here. Generally, I don't want past versions to tell me what versions I need to upgrade to for things like KubeDNS because old versions will tell me the wrong version numbers.

fmt.Fprintf(w, "Note: In order to show accurate upgrade versions, please use kubeadm version %s.\n", upgrade.After.KubeadmVersion)
} else {
fmt.Fprintf(tabw, "Kube DNS\t%s\t%s\n", upgrade.Before.DNSVersion, upgrade.After.DNSVersion)
}
fmt.Fprintf(tabw, "Etcd\t%s\t%s\n", upgrade.Before.EtcdVersion, upgrade.After.EtcdVersion)

// The tabwriter should be flushed at this stage as we have now put in all the required content for this time. This is required for the tabs' size to be correct.
tabw.Flush()
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.Fprintln(w, "")
fmt.Fprintf(w, "Upgrade to the latest %s:\n", upgrade.Description)
fmt.Fprintln(w, "")
fmt.Fprintln(tabw, "COMPONENT\tCURRENT\tAVAILABLE")
fmt.Fprintf(tabw, "API Server\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Controller Manager\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Scheduler\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)
fmt.Fprintf(tabw, "Kube Proxy\t%s\t%s\n", upgrade.Before.KubeVersion, upgrade.After.KubeVersion)

if features.Enabled(featureGates, features.CoreDNS) {
fmt.Fprintf(tabw, "CoreDNS\t%s\t%s\n", upgrade.Before.DNSVersion, upgrade.After.DNSVersion)
} else {
fmt.Fprintf(tabw, "Kube DNS\t%s\t%s\n", upgrade.Before.DNSVersion, upgrade.After.DNSVersion)
}
fmt.Fprintf(tabw, "Etcd\t%s\t%s\n", upgrade.Before.EtcdVersion, upgrade.After.EtcdVersion)

if upgrade.Before.KubeadmVersion != upgrade.After.KubeadmVersion {
fmt.Fprintf(w, "Note: Before you can perform this upgrade, you have to update kubeadm to %s.\n", upgrade.After.KubeadmVersion)
// The tabwriter should be flushed at this stage as we have now put in all the required content for this time. This is required for the tabs' size to be correct.
tabw.Flush()
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.Fprintln(w, "")
fmt.Fprintln(w, "_____________________________________________________________________")
fmt.Fprintln(w, "")
}
Expand Down
78 changes: 27 additions & 51 deletions cmd/kubeadm/app/cmd/upgrade/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ func TestSortedSliceFromStringIntMap(t *testing.T) {
func TestPrintAvailableUpgrades(t *testing.T) {
featureGates := make(map[string]bool)
var tests = []struct {
name string
upgrades []upgrade.Upgrade
buf *bytes.Buffer
expectedBytes []byte
}{
{
name: "no update needed",
upgrades: []upgrade.Upgrade{},
expectedBytes: []byte(`Awesome, you're up-to-date! Enjoy!
`),
},
{
name: "outdated kubeadm and kubelet",
upgrades: []upgrade.Upgrade{
{
Description: "version in the v1.8 series",
Expand All @@ -96,27 +99,14 @@ func TestPrintAvailableUpgrades(t *testing.T) {
COMPONENT CURRENT AVAILABLE
Kubelet 1 x v1.8.1 v1.8.3

Upgrade to the latest version in the v1.8 series:

COMPONENT CURRENT AVAILABLE
API Server v1.8.1 v1.8.3
Controller Manager v1.8.1 v1.8.3
Scheduler v1.8.1 v1.8.3
Kube Proxy v1.8.1 v1.8.3
Kube DNS 1.14.5 1.14.5
Etcd 3.0.17 3.0.17

You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.8.3

Note: Before you can perform this upgrade, you have to update kubeadm to v1.8.3.
Note: In order to show accurate upgrade versions, please use kubeadm version v1.8.3.

_____________________________________________________________________

`),
},
{
name: "outdated kubelet newest kubeadm",
upgrades: []upgrade.Upgrade{
{
Description: "stable version",
Expand Down Expand Up @@ -160,6 +150,7 @@ _____________________________________________________________________
`),
},
{
name: "multiple stable paths",
upgrades: []upgrade.Upgrade{
{
Description: "version in the v1.8 series",
Expand All @@ -168,13 +159,13 @@ _____________________________________________________________________
KubeletVersions: map[string]uint16{
"v1.8.3": 1,
},
KubeadmVersion: "v1.8.3",
KubeadmVersion: "v1.8.5",
DNSVersion: "1.14.5",
EtcdVersion: "3.0.17",
},
After: upgrade.ClusterState{
KubeVersion: "v1.8.5",
KubeadmVersion: "v1.8.3",
KubeadmVersion: "v1.8.5",
DNSVersion: "1.14.5",
EtcdVersion: "3.0.17",
},
Expand Down Expand Up @@ -222,27 +213,14 @@ Components that must be upgraded manually after you have upgraded the control pl
COMPONENT CURRENT AVAILABLE
Kubelet 1 x v1.8.3 v1.9.0

Upgrade to the latest stable version:

COMPONENT CURRENT AVAILABLE
API Server v1.8.3 v1.9.0
Controller Manager v1.8.3 v1.9.0
Scheduler v1.8.3 v1.9.0
Kube Proxy v1.8.3 v1.9.0
Kube DNS 1.14.5 1.14.9
Etcd 3.0.17 3.1.12

You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.9.0

Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.0.
Note: In order to show accurate upgrade versions, please use kubeadm version v1.9.0.

_____________________________________________________________________

`),
},
{
name: "experimental upgrade",
upgrades: []upgrade.Upgrade{
{
Description: "experimental version",
Expand All @@ -251,7 +229,7 @@ _____________________________________________________________________
KubeletVersions: map[string]uint16{
"v1.8.5": 1,
},
KubeadmVersion: "v1.8.5",
KubeadmVersion: "v1.9.0-beta.1",
DNSVersion: "1.14.5",
EtcdVersion: "3.0.17",
},
Expand Down Expand Up @@ -281,13 +259,12 @@ You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.9.0-beta.1

Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.0-beta.1.

_____________________________________________________________________

`),
},
{
name: "release candidate upgrade",
upgrades: []upgrade.Upgrade{
{
Description: "release candidate version",
Expand All @@ -296,7 +273,7 @@ _____________________________________________________________________
KubeletVersions: map[string]uint16{
"v1.8.5": 1,
},
KubeadmVersion: "v1.8.5",
KubeadmVersion: "v1.9.0-rc.1",
DNSVersion: "1.14.5",
EtcdVersion: "3.0.17",
},
Expand Down Expand Up @@ -326,13 +303,12 @@ You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.9.0-rc.1

Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.0-rc.1.

_____________________________________________________________________

`),
},
{
name: "mixed kubelet versions",
upgrades: []upgrade.Upgrade{
{
Description: "version in the v1.9 series",
Expand All @@ -342,7 +318,7 @@ _____________________________________________________________________
"v1.9.2": 1,
"v1.9.3": 2,
},
KubeadmVersion: "v1.9.2",
KubeadmVersion: "v1.9.3",
DNSVersion: "1.14.5",
EtcdVersion: "3.0.17",
},
Expand Down Expand Up @@ -373,23 +349,23 @@ You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.9.3

Note: Before you can perform this upgrade, you have to update kubeadm to v1.9.3.

_____________________________________________________________________

`),
},
}
for _, rt := range tests {
rt.buf = bytes.NewBufferString("")
printAvailableUpgrades(rt.upgrades, rt.buf, featureGates)
actualBytes := rt.buf.Bytes()
if !bytes.Equal(actualBytes, rt.expectedBytes) {
t.Errorf(
"failed PrintAvailableUpgrades:\n\texpected: %q\n\t actual: %q",
string(rt.expectedBytes),
string(actualBytes),
)
}
t.Run(rt.name, func(t *testing.T) {
rt.buf = bytes.NewBufferString("")
printAvailableUpgrades(rt.upgrades, rt.buf, featureGates)
actualBytes := rt.buf.Bytes()
if !bytes.Equal(actualBytes, rt.expectedBytes) {
t.Errorf(
"failed PrintAvailableUpgrades:\n\texpected: %q\n\t actual: %q",
string(rt.expectedBytes),
string(actualBytes),
)
}
})
}
}
9 changes: 1 addition & 8 deletions cmd/kubeadm/app/phases/upgrade/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,13 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
// If the cluster version is lower than the newest patch version, we should inform about the possible upgrade
if patchUpgradePossible(clusterVersion, patchVersion) {

// The kubeadm version has to be upgraded to the latest patch version
newKubeadmVer := patchVersionStr
if kubeadmVersion.AtLeast(patchVersion) {
// In this case, the kubeadm CLI version is new enough. Don't display an update suggestion for kubeadm by making .NewKubeadmVersion equal .CurrentKubeadmVersion
newKubeadmVer = kubeadmVersionStr
}

upgrades = append(upgrades, Upgrade{
Description: description,
Before: beforeState,
After: ClusterState{
KubeVersion: patchVersionStr,
DNSVersion: dns.GetDNSVersion(patchVersion, ActiveDNSAddon(featureGates)),
KubeadmVersion: newKubeadmVer,
KubeadmVersion: patchVersionStr,
EtcdVersion: getSuggestedEtcdVersion(patchVersionStr),
// KubeletVersions is unset here as it is not used anywhere in .After
},
Expand Down