Skip to content

Commit f7006de

Browse files
authored
Merge pull request #13276 from fabriziopandini/simplify-GetUpgradePlanFromClusterClassVersions
🌱 Simplify GetUpgradePlanFromClusterClassVersions
2 parents e2454a2 + 9f23a2e commit f7006de

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

exp/topology/desiredstate/upgrade_plan.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,23 +373,30 @@ func GetUpgradePlanFromClusterClassVersions(clusterClassVersions []string) func(
373373
return nil, nil, nil
374374
}
375375

376-
// Pick all the known kubernetes versions starting from control plane version (excluded) to desired version.
376+
// Pick all the candidate kubernetes versions starting from control plane version (excluded) to desired version.
377377
upgradePlan := []string{}
378-
start := false
379-
end := false
380378
for _, v := range clusterClassVersions {
381379
semV, err := semver.ParseTolerant(v)
382380
if err != nil {
383381
return nil, nil, errors.Wrapf(err, "failed to parse version %s", v)
384382
}
385-
if (start && !end) || (!start && semV.Minor > currentControlPlaneSemVer.Minor) {
386-
upgradePlan = append(upgradePlan, v)
383+
// Ignore all candidate version older or equal to the current control plane version;
384+
// also ignoring same versions but with different build tags, because those version will never
385+
// end up in the computed upgrade plan (it starts from the next minor).
386+
if version.Compare(semV, currentControlPlaneSemVer) <= 0 {
387+
continue
387388
}
388-
if semV.String() == currentControlPlaneSemVer.String() || version.Compare(currentControlPlaneSemVer, semV, version.WithBuildTags()) < 0 {
389-
start = true
389+
// Safeguard to stop collecting candidate version when we are past desired version.
390+
// Note This should never happen because web hook enforcing that the desired version is in the list of versions.
391+
if version.Compare(semV, desiredSemVer, version.WithBuildTags()) == 1 {
392+
break
390393
}
391-
if semV.String() == desiredSemVer.String() || version.Compare(desiredSemVer, semV, version.WithBuildTags()) < 0 {
392-
end = true
394+
395+
upgradePlan = append(upgradePlan, v)
396+
397+
// Stop collecting candidate version when we arrive at the desired version.
398+
if semV.String() == desiredSemVer.String() {
399+
break
393400
}
394401
}
395402

exp/topology/desiredstate/upgrade_plan_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,21 @@ func TestGetUpgradePlanFromClusterClassVersions(t *testing.T) {
10901090
wantWorkersUpgradePlan: nil,
10911091
wantErr: false,
10921092
},
1093+
{
1094+
name: "version with not sortable build tags",
1095+
clusterClassVersions: []string{
1096+
"v1.31.0+a", "v1.31.0+b", "v1.31.0+c", // this is the same minor of currentControlPlaneVersion, everything should be ignored.
1097+
"v1.31.1+a",
1098+
"v1.32.0+a", "v1.32.0+b", "v1.32.0+c",
1099+
"v1.33.0+b",
1100+
"v1.33.1+a", "v1.33.1+b", "v1.33.1+c", // desiredVersion ends with +b, +c should be ignored.
1101+
},
1102+
desiredVersion: "v1.33.1+b",
1103+
currentControlPlaneVersion: "v1.31.0+b",
1104+
wantControlPlaneUpgradePlan: []string{"v1.32.0+c", "v1.33.1+b"},
1105+
wantWorkersUpgradePlan: nil,
1106+
wantErr: false,
1107+
},
10931108

10941109
// Kubernetes versions in CC is set when clusters already exists
10951110

0 commit comments

Comments
 (0)