Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions pkg/payload/precondition/clusterversion/recommendedupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -61,15 +62,17 @@ 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{
Reason: condition.Reason,
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,
}
}
}
Expand All @@ -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,
}
}
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions pkg/payload/precondition/precondition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, this could be a godoc, instead of a non-structured comment, but 🤷

}

// Error returns the message
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/payload/precondition/precondition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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`,
Expand Down