From 481bcde393f244f4e4245ebec6a43941c87626de Mon Sep 17 00:00:00 2001 From: Lalatendu Mohanty Date: Fri, 21 Oct 2022 15:14:33 -0400 Subject: [PATCH] OCPBUGS-2727: Do not fail precondition check for UnknownUpdate With this change we will not fail precondition checks when a version is not in available updates. So users should be able to upgrade to any version with approriate client side overrides. For example using --allow-explicit-upgrade and --to-imge flags in "oc adm upgrade" Signed-off-by: Lalatendu Mohanty --- .../clusterversion/recommendedupdate.go | 29 +++++++++++-------- pkg/payload/precondition/precondition.go | 17 +++++++---- pkg/payload/precondition/precondition_test.go | 4 +-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/pkg/payload/precondition/clusterversion/recommendedupdate.go b/pkg/payload/precondition/clusterversion/recommendedupdate.go index 4821c21de2..8a07ae255c 100644 --- a/pkg/payload/precondition/clusterversion/recommendedupdate.go +++ b/pkg/payload/precondition/clusterversion/recommendedupdate.go @@ -37,10 +37,11 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio } if err != nil { return &precondition.Error{ - Nested: err, - Reason: "UnknownError", - Message: err.Error(), - Name: ru.Name(), + Nested: err, + Reason: "UnknownError", + Message: err.Error(), + Name: ru.Name(), + NonBlockingWarning: true, } } for _, recommended := range clusterVersion.Status.AvailableUpdates { @@ -61,7 +62,8 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio Reason: condition.Reason, Message: fmt.Sprintf("Update from %s to %s is not recommended:\n\n%s", clusterVersion.Status.Desired.Version, releaseContext.DesiredVersion, condition.Message), - Name: ru.Name(), + Name: ru.Name(), + NonBlockingWarning: true, } default: return &precondition.Error{ @@ -69,7 +71,8 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio Message: fmt.Sprintf("Update from %s to %s is %s=%s: %s: %s", clusterVersion.Status.Desired.Version, releaseContext.DesiredVersion, condition.Type, condition.Status, condition.Reason, condition.Message), - Name: ru.Name(), + Name: ru.Name(), + NonBlockingWarning: true, } } } @@ -78,7 +81,8 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio Reason: "UnknownConditionType", Message: fmt.Sprintf("Update from %s to %s has a status.conditionalUpdates entry, but no Recommended condition.", clusterVersion.Status.Desired.Version, releaseContext.DesiredVersion), - Name: ru.Name(), + Name: ru.Name(), + NonBlockingWarning: true, } } } @@ -88,13 +92,13 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio Reason: "NoChannel", Message: fmt.Sprintf("Configured channel is unset, so the recommended status of updating from %s to %s is unknown.", clusterVersion.Status.Desired.Version, releaseContext.DesiredVersion), - Name: ru.Name(), + Name: ru.Name(), + NonBlockingWarning: true, } } reason := "UnknownUpdate" msg := "" - if retrieved := resourcemerge.FindOperatorStatusCondition(clusterVersion.Status.Conditions, configv1.RetrievedUpdates); retrieved == nil { msg = fmt.Sprintf("No %s, so the recommended status of updating from %s to %s is unknown.", configv1.RetrievedUpdates, clusterVersion.Status.Desired.Version, releaseContext.DesiredVersion) @@ -108,9 +112,10 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio if msg != "" { return &precondition.Error{ - Reason: reason, - Message: msg, - Name: ru.Name(), + Reason: reason, + Message: msg, + Name: ru.Name(), + NonBlockingWarning: true, } } return nil diff --git a/pkg/payload/precondition/precondition.go b/pkg/payload/precondition/precondition.go index 5daa1d47ec..f421ed44ed 100644 --- a/pkg/payload/precondition/precondition.go +++ b/pkg/payload/precondition/precondition.go @@ -12,10 +12,11 @@ import ( // Error is a wrapper for errors that occur during a precondition check for payload. type Error struct { - Nested error - Reason string - Message string - Name string + Nested error + Reason string + Message string + Name string + NonBlockingWarning bool // For some errors we do not want to fail the precondition check but we want to communicate about it } // Error returns the message @@ -71,12 +72,17 @@ func Summarize(errs []error, force bool) (bool, error) { return false, nil } var msgs []string + var isWarning = true for _, e := range errs { if pferr, ok := e.(*Error); ok { msgs = append(msgs, fmt.Sprintf("Precondition %q failed because of %q: %v", pferr.Name, pferr.Reason, pferr.Error())) + if !pferr.NonBlockingWarning { + isWarning = false + } continue } msgs = append(msgs, e.Error()) + } msg := "" if len(msgs) == 1 { @@ -87,9 +93,10 @@ func Summarize(errs []error, force bool) (bool, error) { if force { msg = fmt.Sprintf("Forced through blocking failures: %s", msg) + isWarning = true } - return !force, &payload.UpdateError{ + return !isWarning, &payload.UpdateError{ Nested: nil, Reason: "UpgradePreconditionCheckFailed", Message: msg, diff --git a/pkg/payload/precondition/precondition_test.go b/pkg/payload/precondition/precondition_test.go index 015a41cfd7..192a0a56ba 100644 --- a/pkg/payload/precondition/precondition_test.go +++ b/pkg/payload/precondition/precondition_test.go @@ -21,7 +21,7 @@ func TestSummarize(t *testing.T) { }, { name: "unrecognized error type", errors: []error{fmt.Errorf("random error")}, - expectedBlock: true, + expectedBlock: false, expectedError: "random error", }, { name: "forced unrecognized error type", @@ -42,7 +42,7 @@ func TestSummarize(t *testing.T) { }, { name: "two unrecognized error types", errors: []error{fmt.Errorf("random error"), fmt.Errorf("random error 2")}, - expectedBlock: true, + expectedBlock: false, expectedError: `Multiple precondition checks failed: * random error * random error 2`,