Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Make handling Kubernetes versions easier #2506

Merged
merged 7 commits into from
Mar 23, 2018

Conversation

jackfrancis
Copy link
Member

@jackfrancis jackfrancis commented Mar 21, 2018

What this PR does / why we need it: Expands version generics and gets rid of static consts so we can more fluidly and easily evolve w/ newer Kubernetes versions going forward.

This PR will mean that to add support for future Kubernetes versions we maintain a single map (AllKubernetesSupportedVersions in pkg/api/common)

Release note:

rationalize Kubernetes version support handling

@jackfrancis jackfrancis force-pushed the version-rev-rationalization branch from fb7b169 to a248dd4 Compare March 21, 2018 22:32
so we don’t have to define version whitelist twice
@jackfrancis jackfrancis changed the title WIP: Make handling Kubernetes versions easier Make handling Kubernetes versions easier Mar 21, 2018
@@ -53,120 +57,48 @@ const (
)

const (
// KubernetesVersion1Dot10Dot0RC1 is the string for kubernetes 1.10.0-rc.1
Copy link
Member Author

Choose a reason for hiding this comment

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

These consts were not adding to readability/maintainability, and runtime optimization is not a concern

KubernetesVersion1Dot10Dot0RC1: false,
var AllKubernetesWindowsSupportedVersions = getAllKubernetesWindowsSupportedVersionsMap()

func getAllKubernetesWindowsSupportedVersionsMap() map[string]bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of Windows support being a mostly duplicated whitelist of the larger support matrix, this is now an override/blackslist

t.Errorf("It is not the default Kubernetes version")
}

version = GetValidPatchVersion(Kubernetes, "1.6.3")
Copy link
Member Author

Choose a reason for hiding this comment

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

All of these static tests tied to most recent patch versions were suggesting that there was some significance to testing the most recent patch version in these unit tests. In fact this unit test should be maintained independently of kubernets release version particulars.

if v != version {
t.Errorf("Expected version %s, instead got version %s", version, v)
}
}
}
}

func TestGetLatestPatchVersion(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

ditto above

@@ -78,39 +46,31 @@ func Test_RationalizeReleaseAndVersion(t *testing.T) {
t.Errorf("It is not the default Kubernetes version")
}

latest1Dot6Version := GetLatestPatchVersion("1.6", GetAllSupportedKubernetesVersions())
Copy link
Member Author

Choose a reason for hiding this comment

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

We already have conveniences to grab the latest version in a major.minor release channel, so we don't need to be maintaining them statically to validate "orchestratorRelease" behavior.

if o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot6 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot9 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot11 {
sv, _ := semver.NewVersion(o.OrchestratorVersion)
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually validating what our error condition suggests we're validating. :)

if o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot6 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot9 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot11 {
sv, _ := semver.NewVersion(o.OrchestratorVersion)
Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot12 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot13 ||
o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot14 {
sv, _ := semver.NewVersion(o.OrchestratorVersion)
Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

@@ -235,22 +224,6 @@ func (o *OrchestratorVersionProfile) Validate() error {
return o.OrchestratorProfile.Validate(false)
}

// ValidateForUpgrade validates upgrade input data
Copy link
Member Author

Choose a reason for hiding this comment

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

This function is never referenced.

@@ -259,10 +259,7 @@ func Test_KubernetesConfig_Validate(t *testing.T) {
}

// Tests that apply to 1.6 and later releases
for _, k8sVersion := range []string{common.KubernetesVersion1Dot6Dot11, common.KubernetesVersion1Dot6Dot12, common.KubernetesVersion1Dot6Dot13,
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't believe we've been maintaining this string slice literal

@@ -274,7 +271,7 @@ func Test_KubernetesConfig_Validate(t *testing.T) {

trueVal := true
// Tests that apply to 1.8 and later releases
for _, k8sVersion := range []string{common.KubernetesVersion1Dot8Dot1} {
Copy link
Member Author

Choose a reason for hiding this comment

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

Yikes we were never doing what we said

@CecileRobertMichon
Copy link
Contributor

CecileRobertMichon commented Mar 22, 2018

Is there any way to make this go away? (and the other 2 const checks)

Expect(len(list.Properties.Orchestrators)).To(Equal(36))

(I know I'm asking for extra credit, your PR is already great as-is)

if cons.Check(sv) {
ret = append(ret, v)
}
}
return ret
}

// GetVersionsLt returns a list of versions greater than a semver string given a list of versions
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just me or should this function be called GetVersionsGt?

Copy link
Contributor

Choose a reason for hiding this comment

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

scratch that, the comment should be returns a list of versions lesser than a semver string


// v20170930 - kubernetes only
list, e = GetOrchestratorVersionProfileListV20170930(common.Kubernetes, "")
Expect(e).To(BeNil())
Expect(len(list.Properties.Orchestrators)).To(Equal(36))
Expect(len(list.Properties.Orchestrators)).To(Equal(len(common.GetAllSupportedKubernetesVersions())))
Copy link
Contributor

Choose a reason for hiding this comment

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

💯


// 1.10.0-rc.1 is not upgradable
// The latest version is not upgradable
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

lgtm

@jackfrancis jackfrancis merged commit a29c718 into Azure:master Mar 23, 2018
@ghost ghost removed the in progress label Mar 23, 2018
@jackfrancis jackfrancis deleted the version-rev-rationalization branch March 23, 2018 20:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants