@@ -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
0 commit comments