Skip to content

Commit 07c1bb8

Browse files
committed
pkg/payload/precondition/clusterversion: MajorVersionClusterUpdateInProgress
David pointed out [1] that the existing MinorVersionClusterUpdateInProgress needed to be extended to have a major-version update form too. [1]: #1276 (comment)
1 parent f007065 commit 07c1bb8

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

pkg/payload/precondition/clusterversion/upgradeable.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package clusterversion
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
"github.com/blang/semver/v4"
@@ -108,11 +109,11 @@ func (pf *Upgradeable) Run(ctx context.Context, releaseContext precondition.Rele
108109
Name: pf.Name(),
109110
}
110111
} else {
111-
if completedVersion := minorUpdateFrom(cv.Status, currentVersion); completedVersion != "" && patchOnly {
112+
if completedVersion, majorOrMinor := majorOrMinorUpdateFrom(cv.Status, currentVersion); completedVersion != "" && patchOnly {
112113
// This is to generate an accepted risk for the accepting case 4.y.z -> 4.y+1.z' -> 4.y+1.z''
113114
return &precondition.Error{
114-
Reason: "MinorVersionClusterUpdateInProgress",
115-
Message: fmt.Sprintf("Retarget to %s while a minor version update from %s to %s is in progress", targetVersion, completedVersion, currentVersion),
115+
Reason: fmt.Sprintf("%sVersionClusterUpdateInProgress", majorOrMinor),
116+
Message: fmt.Sprintf("Retarget to %s while a %s version update from %s to %s is in progress", targetVersion, strings.ToLower(majorOrMinor), completedVersion, currentVersion),
116117
Name: pf.Name(),
117118
NonBlockingWarning: true,
118119
}
@@ -130,24 +131,29 @@ func (pf *Upgradeable) Run(ctx context.Context, releaseContext precondition.Rele
130131
}
131132
}
132133

133-
// minorUpdateFrom returns the version that was installed completed if a minor version upgrade is in progress
134-
// and the empty string otherwise
135-
func minorUpdateFrom(status configv1.ClusterVersionStatus, currentVersion semver.Version) string {
134+
// majorOrMinorUpdateFrom returns the version that was installed
135+
// completed if a minor or major version upgrade is in progress and the
136+
// empty string otherwise. It also returns "Major", "Minor", or "" to name
137+
// the transition.
138+
func majorOrMinorUpdateFrom(status configv1.ClusterVersionStatus, currentVersion semver.Version) (string, string) {
136139
completedVersion := GetCurrentVersion(status.History)
137140
if completedVersion == "" {
138-
return ""
141+
return "", ""
139142
}
140143
v, err := semver.Parse(completedVersion)
141144
if err != nil {
142-
return ""
145+
return "", ""
143146
}
144147
if cond := resourcemerge.FindOperatorStatusCondition(status.Conditions, configv1.OperatorProgressing); cond != nil &&
145-
cond.Status == configv1.ConditionTrue &&
146-
v.Major == currentVersion.Major &&
147-
v.Minor < currentVersion.Minor {
148-
return completedVersion
148+
cond.Status == configv1.ConditionTrue {
149+
if v.Major < currentVersion.Major {
150+
return completedVersion, "Major"
151+
}
152+
if v.Major == currentVersion.Major && v.Minor < currentVersion.Minor {
153+
return completedVersion, "Minor"
154+
}
149155
}
150-
return ""
156+
return "", ""
151157
}
152158

153159
// Name returns the name of the precondition.

pkg/payload/precondition/clusterversion/upgradeable_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ func TestUpgradeableRun(t *testing.T) {
140140
Reason: "MinorVersionClusterUpdateInProgress",
141141
},
142142
},
143+
{
144+
name: "move-x-then-z, with false condition",
145+
upgradeable: ptr(configv1.ConditionFalse),
146+
completedVersion: "4.1.1",
147+
currVersion: "5.0.1",
148+
desiredVersion: "5.0.3",
149+
expected: &precondition.Error{
150+
NonBlockingWarning: true,
151+
Name: "ClusterVersionUpgradeable",
152+
Message: "Retarget to 5.0.3 while a major version update from 4.1.1 to 5.0.1 is in progress",
153+
Reason: "MajorVersionClusterUpdateInProgress",
154+
},
155+
},
143156
{
144157
name: "move-z-then-z, with false condition",
145158
upgradeable: ptr(configv1.ConditionFalse),

0 commit comments

Comments
 (0)