Propagate error from NewREST

This commit is contained in:
Ted Yu
2019-08-12 13:55:33 -07:00
committed by Ted Yu
parent c981c65c90
commit 87b2a3129b
100 changed files with 917 additions and 408 deletions

View File

@@ -48,14 +48,17 @@ type ControllerStorage struct {
Scale *ScaleREST
}
func NewStorage(optsGetter generic.RESTOptionsGetter) ControllerStorage {
controllerREST, statusREST := NewREST(optsGetter)
func NewStorage(optsGetter generic.RESTOptionsGetter) (ControllerStorage, error) {
controllerREST, statusREST, err := NewREST(optsGetter)
if err != nil {
return ControllerStorage{}, err
}
return ControllerStorage{
Controller: controllerREST,
Status: statusREST,
Scale: &ScaleREST{store: controllerREST.Store},
}
}, nil
}
type REST struct {
@@ -63,7 +66,7 @@ type REST struct {
}
// NewREST returns a RESTStorage object that will work against replication controllers.
func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST) {
func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) {
store := &genericregistry.Store{
NewFunc: func() runtime.Object { return &api.ReplicationController{} },
NewListFunc: func() runtime.Object { return &api.ReplicationControllerList{} },
@@ -78,13 +81,13 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST) {
}
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: replicationcontroller.GetAttrs}
if err := store.CompleteWithOptions(options); err != nil {
panic(err) // TODO: Propagate error up
return nil, nil, err
}
statusStore := *store
statusStore.UpdateStrategy = replicationcontroller.StatusStrategy
return &REST{store}, &StatusREST{store: &statusStore}
return &REST{store}, &StatusREST{store: &statusStore}, nil
}
// Implement ShortNamesProvider

View File

@@ -49,7 +49,10 @@ func newStorage(t *testing.T) (ControllerStorage, *etcd3testing.EtcdTestServer)
DeleteCollectionWorkers: 1,
ResourcePrefix: "replicationcontrollers",
}
storage := NewStorage(restOptions)
storage, err := NewStorage(restOptions)
if err != nil {
t.Fatalf("unexpected error from REST storage: %v", err)
}
return storage, server
}