@@ -3,6 +3,7 @@ package clusterversion
33import (
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.
0 commit comments