mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #64008 from dixudx/fix_kubeadm_get_branch
Automatic merge from submit-queue (batch tested with PRs 60012, 63692, 63977, 63960, 64008). 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>. uses a more resilient way to get branch name from version **What this PR does / why we need it**: Currently `getBranchFromVersion` uses a hard coded way to extract branch name from the version string. This is error prone, especially when bumping the minimum supported k8s version from v1.9 to v1.10. This follow-up PR tries to use a more resilient way to handle this. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: xref #63920 **Special notes for your reviewer**: /cc luxas timothysc **Release note**: ```release-note None ```
This commit is contained in:
commit
6187898b60
@ -25,7 +25,7 @@ import (
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns"
|
||||
etcdutil "k8s.io/kubernetes/cmd/kubeadm/app/util/etcd"
|
||||
"k8s.io/kubernetes/pkg/util/version"
|
||||
versionutil "k8s.io/kubernetes/pkg/util/version"
|
||||
)
|
||||
|
||||
// Upgrade defines an upgrade possibility to upgrade from a current version to a new one
|
||||
@ -279,22 +279,23 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
|
||||
}
|
||||
|
||||
func getBranchFromVersion(version string) string {
|
||||
return strings.TrimPrefix(version, "v")[:4]
|
||||
v := versionutil.MustParseGeneric(version)
|
||||
return fmt.Sprintf("%d.%d", v.Major(), v.Minor())
|
||||
}
|
||||
|
||||
func patchVersionBranchExists(clusterVersion, stableVersion *version.Version) bool {
|
||||
func patchVersionBranchExists(clusterVersion, stableVersion *versionutil.Version) bool {
|
||||
return stableVersion.AtLeast(clusterVersion)
|
||||
}
|
||||
|
||||
func patchUpgradePossible(clusterVersion, patchVersion *version.Version) bool {
|
||||
func patchUpgradePossible(clusterVersion, patchVersion *versionutil.Version) bool {
|
||||
return clusterVersion.LessThan(patchVersion)
|
||||
}
|
||||
|
||||
func rcUpgradePossible(clusterVersion, previousBranchLatestVersion *version.Version) bool {
|
||||
func rcUpgradePossible(clusterVersion, previousBranchLatestVersion *versionutil.Version) bool {
|
||||
return strings.HasPrefix(previousBranchLatestVersion.PreRelease(), "rc") && clusterVersion.LessThan(previousBranchLatestVersion)
|
||||
}
|
||||
|
||||
func minorUpgradePossibleWithPatchRelease(stableVersion, patchVersion *version.Version) bool {
|
||||
func minorUpgradePossibleWithPatchRelease(stableVersion, patchVersion *versionutil.Version) bool {
|
||||
return patchVersion.LessThan(stableVersion)
|
||||
}
|
||||
|
||||
|
@ -826,3 +826,56 @@ func TestKubeletUpgrade(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBranchFromVersion(t *testing.T) {
|
||||
testCases := []struct {
|
||||
version string
|
||||
expectedVersion string
|
||||
}{
|
||||
{
|
||||
version: "v1.9.5",
|
||||
expectedVersion: "1.9",
|
||||
},
|
||||
{
|
||||
version: "v1.9.0-alpha.2",
|
||||
expectedVersion: "1.9",
|
||||
},
|
||||
{
|
||||
version: "v1.9.0-beta.0",
|
||||
expectedVersion: "1.9",
|
||||
},
|
||||
{
|
||||
version: "v1.9.0-rc.1",
|
||||
expectedVersion: "1.9",
|
||||
},
|
||||
{
|
||||
version: "v1.12.5",
|
||||
expectedVersion: "1.12",
|
||||
},
|
||||
{
|
||||
version: "v1.11.0-alpha.0",
|
||||
expectedVersion: "1.11",
|
||||
},
|
||||
|
||||
{
|
||||
version: "v1.11.0-beta.1",
|
||||
expectedVersion: "1.11",
|
||||
},
|
||||
{
|
||||
version: "v1.11.0-rc.0",
|
||||
expectedVersion: "1.11",
|
||||
},
|
||||
{
|
||||
version: "1.12.5",
|
||||
expectedVersion: "1.12",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
v := getBranchFromVersion(tc.version)
|
||||
if v != tc.expectedVersion {
|
||||
t.Errorf("expected version %s, got %s", tc.expectedVersion, v)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user