Skip to content

Commit 7316d19

Browse files
Fixing review comments: Added more conditional loops to cover more usecases
Will merge this to a single commit before merge Signed-off-by: Lalatendu Mohanty <[email protected]>
1 parent a6807ee commit 7316d19

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

pkg/cli/admin/upgrade/upgrade.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func (o *Options) Run() error {
235235

236236
case len(o.To) > 0, len(o.ToImage) > 0:
237237
var update *configv1.Update
238+
var conditionalUpdate *configv1.Update
238239
if len(o.To) > 0 {
239240
if o.To == cv.Status.Desired.Version {
240241
fmt.Fprintf(o.Out, "info: Cluster is already at version %s\n", o.To)
@@ -249,33 +250,48 @@ func (o *Options) Run() error {
249250
break
250251
}
251252
}
252-
if o.AllowNotRecommended {
253-
for _, upgrade := range cv.Status.ConditionalUpdates {
254-
if c := findCondition(upgrade.Conditions, "Recommended"); c != nil && c.Status != metav1.ConditionTrue {
255-
if upgrade.Release.Version == o.To {
256-
update = &configv1.Update{
257-
Version: upgrade.Release.Version,
258-
Image: upgrade.Release.Image,
259-
}
253+
254+
// Check if the --to version present in condiional update
255+
for _, upgrade := range cv.Status.ConditionalUpdates {
256+
if c := findCondition(upgrade.Conditions, "Recommended"); c != nil && c.Status != metav1.ConditionTrue {
257+
if upgrade.Release.Version == o.To {
258+
conditionalUpdate = &configv1.Update{
259+
Version: upgrade.Release.Version,
260+
Image: upgrade.Release.Image,
261+
}
262+
if o.AllowNotRecommended {
260263
fmt.Fprintf(o.ErrOut, "warning: with --allow-not-recommended you have accepted the risks with %s and bypassing %s=%s %s: %s\n", o.To, c.Type, c.Status, c.Reason, c.Message)
261-
break
262264
}
265+
break
263266
}
264267
}
265268
}
266-
if update == nil {
269+
270+
switch {
271+
case update == nil && conditionalUpdate == nil:
267272
if len(cv.Status.AvailableUpdates) == 0 {
268273
if c := findClusterOperatorStatusCondition(cv.Status.Conditions, configv1.RetrievedUpdates); c != nil && c.Status == configv1.ConditionFalse {
269274
return fmt.Errorf("Can't look up image for version %s. %v", o.To, c.Message)
270275
}
271-
return fmt.Errorf("No available updates, specify --to-image or wait for new updates to be available")
276+
return fmt.Errorf("No recommended or conditional updates, specify --to-image or wait for new updates to be available")
272277
}
278+
return fmt.Errorf("The update %s is not one of the recommended or conditional updates", o.To)
279+
case update == nil && conditionalUpdate != nil:
280+
if !o.AllowNotRecommended {
281+
return fmt.Errorf("The update %s is not one of the recommended updates. But it is available as a conditional update. To accept the risk and to proceed with update use --allow-not-recommended flag", o.To)
282+
}
283+
case update != nil && conditionalUpdate == nil:
273284
if o.AllowNotRecommended {
274-
return fmt.Errorf("The update %s is not one of the conditional or recommended updates", o.To)
285+
return fmt.Errorf("The update %s is not available as a conditional update but available as a recommended update. To proceed with the update do not use --allow-not-recommended flag", o.To)
275286
}
276-
return fmt.Errorf("The update %s is not one of the available updates: %s", o.To, strings.Join(versionStrings(cv.Status.AvailableUpdates), ", "))
287+
}
288+
289+
//if user has used --allow-not-recommended and the version is present in conditional edges then the update should proceed
290+
if o.AllowNotRecommended {
291+
update = conditionalUpdate
277292
}
278293
}
294+
279295
if len(o.ToImage) > 0 {
280296
var found bool
281297
for _, available := range cv.Status.AvailableUpdates {

0 commit comments

Comments
 (0)