Skip to content
Merged
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
34 changes: 33 additions & 1 deletion pkg/cvo/sync_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"sync"
"time"

"k8s.io/klog"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/time/rate"
"k8s.io/klog"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -751,12 +751,44 @@ func summarizeTaskGraphErrors(errs []error) error {
if len(errs) == 1 {
return errs[0]
}
// hide the generic "not available yet" when there are more specific errors present
if filtered := filterErrors(errs, isClusterOperatorNotAvailable); len(filtered) > 0 {
return newMultipleError(filtered)
}
// if we're only waiting for operators, condense the error down to a singleton
if err := newClusterOperatorsNotAvailable(errs); err != nil {
return err
}
return newMultipleError(errs)
Copy link
Member

Choose a reason for hiding this comment

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

This is the only newMultipleErrors consumer. It feels strange to have some preprocessing locally; can we add this new logic inside newMultipleErrors (and drop the local collapse, since newMultipleErrors already does that internally)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s three different flows - I expect there to be more in the future. MultipleErrors is for when we don’t know anything

}

// filterErrors returns only the errors in errs which are false for all fns.
func filterErrors(errs []error, fns ...func(err error) bool) []error {
var filtered []error
for _, err := range errs {
if errorMatches(err, fns...) {
continue
}
filtered = append(filtered, err)
}
return filtered
}

func errorMatches(err error, fns ...func(err error) bool) bool {
for _, fn := range fns {
if fn(err) {
return true
}
}
return false
}

// isClusterOperatorNotAvailable returns true if this is a ClusterOperatorNotAvailable error
func isClusterOperatorNotAvailable(err error) bool {
uErr, ok := err.(*payload.UpdateError)
return ok && uErr != nil && uErr.Reason == "ClusterOperatorNotAvailable"
}

// newClusterOperatorsNotAvailable unifies multiple ClusterOperatorNotAvailable errors into
// a single error. It returns nil if the provided errors are not of the same type.
func newClusterOperatorsNotAvailable(errs []error) error {
Expand Down