Skip to content

Commit

Permalink
Panic in FakeClient if objects fail to add
Browse files Browse the repository at this point in the history
User code may use this fake client in tests without setting up logging,
making errors here extremely difficult to track down. Panic logs more
reliably with better debugging details.
  • Loading branch information
grantr committed Apr 4, 2019
1 parent 90226f9 commit 43e769a
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -32,14 +31,9 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
"sigs.k8s.io/controller-runtime/pkg/internal/objectutil"
)

var (
log = logf.RuntimeLog.WithName("fake-client")
)

type fakeClient struct {
tracker testing.ObjectTracker
scheme *runtime.Scheme
Expand All @@ -63,9 +57,7 @@ func NewFakeClientWithScheme(clientScheme *runtime.Scheme, initObjs ...runtime.O
for _, obj := range initObjs {
err := tracker.Add(obj)
if err != nil {
log.Error(err, "failed to add object to fake client", "object", obj)
os.Exit(1)
return nil
panic(fmt.Errorf("failed to add object %v to fake client: %v", obj, err))
}
}
return &fakeClient{
Expand Down

0 comments on commit 43e769a

Please sign in to comment.