diff --git a/testing/upgradetest/versions.go b/testing/upgradetest/versions.go index ff13ac18ebc..9be4854028f 100644 --- a/testing/upgradetest/versions.go +++ b/testing/upgradetest/versions.go @@ -188,6 +188,7 @@ func findRequiredVersions(sortedParsedVersions []*version.ParsedSemVer, reqs Ver currentMajor := parsedUpgradeToVersion.Major() currentMinor := parsedUpgradeToVersion.Minor() + skipCurrentMajor := false currentMajorsToFind := reqs.CurrentMajors previousMajorsToFind := reqs.PreviousMajors previousMinorsToFind := reqs.PreviousMinors @@ -214,7 +215,7 @@ func findRequiredVersions(sortedParsedVersions []*version.ParsedSemVer, reqs Ver currentMajorsToFind-- // counts as the current major as well // current majors - case currentMajorsToFind > 0 && version.Major() == currentMajor: + case currentMajorsToFind > 0 && version.Major() == currentMajor && !skipCurrentMajor: upgradableVersions = append(upgradableVersions, version.String()) currentMajorsToFind-- @@ -222,7 +223,10 @@ func findRequiredVersions(sortedParsedVersions []*version.ParsedSemVer, reqs Ver case previousMajorsToFind > 0 && version.Major() < currentMajor: upgradableVersions = append(upgradableVersions, version.String()) currentMajor = version.Major() + currentMinor = version.Minor() previousMajorsToFind-- + previousMinorsToFind-- // count as prev minor as well + skipCurrentMajor = true // since the list is sorted we can stop here default: @@ -252,7 +256,13 @@ func PreviousMinor() (*version.ParsedSemVer, error) { // will only contain minors from the previous major (vX-1). Further, since the // version list is sorted in descending order (newer versions first), we can return the // first item from the list as it will be the newest minor of the previous major. - return versions[0], nil + for _, v := range versions { + if v.Less(*current) { + return v, nil + } + } + + return nil, ErrNoPreviousMinor } for _, v := range versions {