diff --git a/internal/controller/sharded.go b/internal/controller/sharded.go index 0b7bbff..756c8cc 100644 --- a/internal/controller/sharded.go +++ b/internal/controller/sharded.go @@ -48,14 +48,13 @@ func (r *StCtrlErrSet) AsResult() (ctrl.Result, error) { if r.Update != nil { errMap["update-status"] = r.Update } - mergedErr := util.MergeErrorsWithTag(errMap) - if mergedErr == nil { + if len(errMap) == 0 { if updateConflict { return ctrl.Result{Requeue: true}, nil } else { return ctrl.Result{}, nil } } else { - return ctrl.Result{Requeue: true}, mergedErr + return ctrl.Result{Requeue: true}, &util.MultiTaggedError{Errors: errMap} } } diff --git a/internal/util/mutierror.go b/internal/util/mutierror.go index 1f60f51..e337e07 100644 --- a/internal/util/mutierror.go +++ b/internal/util/mutierror.go @@ -99,17 +99,3 @@ func (e *MultiTaggedError) Error() string { } return strings.Join(errStrs, "; ") } - -// MergeErrorsWithTag merges multiple errors into one with tags. -func MergeErrorsWithTag(errors map[string]error) *MultiTaggedError { - errMap := make(map[string]error) - for tag, err := range errors { - if err != nil { - errMap[tag] = err - } - } - if len(errMap) == 0 { - return nil - } - return &MultiTaggedError{Errors: errMap} -} diff --git a/internal/util/mutierror_test.go b/internal/util/mutierror_test.go index 38c909b..c7d0483 100644 --- a/internal/util/mutierror_test.go +++ b/internal/util/mutierror_test.go @@ -20,9 +20,9 @@ package util import ( "fmt" - "github.com/stretchr/testify/assert" - "k8s.io/utils/strings/slices" "testing" + + "github.com/stretchr/testify/assert" ) func TestMergeErrors(t *testing.T) { @@ -38,23 +38,3 @@ func TestMergeErrors(t *testing.T) { err4 := MergeErrors(nil, nil) assert.Nil(t, err4) } - -func TestMergeErrorsWithTags(t *testing.T) { - err1 := MergeErrorsWithTag(map[string]error{ - "tag1": fmt.Errorf("foo"), - "tag2": fmt.Errorf("bar"), - }) - assert.True(t, slices.Contains([]string{"[tag1] foo; [tag2] bar", "[tag2] bar; [tag1] foo"}, err1.Error())) - - err2 := MergeErrorsWithTag(map[string]error{ - "tag1": fmt.Errorf("foo"), - "tag2": nil, - }) - assert.Equal(t, "[tag1] foo", err2.Error()) - - err3 := MergeErrorsWithTag(map[string]error{ - "tag1": nil, - "tag2": nil, - }) - assert.Nil(t, err3) -}