mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Propagate error when creating CustomResourceStorage instead of panic'ing
This commit is contained in:
parent
30ea0d13cd
commit
796690637d
@ -818,7 +818,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
|||||||
return nil, fmt.Errorf("the server could not properly serve the list kind")
|
return nil, fmt.Errorf("the server could not properly serve the list kind")
|
||||||
}
|
}
|
||||||
|
|
||||||
storages[v.Name] = customresource.NewStorage(
|
storages[v.Name], err = customresource.NewStorage(
|
||||||
resource.GroupResource(),
|
resource.GroupResource(),
|
||||||
singularResource.GroupResource(),
|
singularResource.GroupResource(),
|
||||||
kind,
|
kind,
|
||||||
@ -847,6 +847,9 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
|||||||
table,
|
table,
|
||||||
replicasPathInCustomResource,
|
replicasPathInCustomResource,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
clusterScoped := crd.Spec.Scope == apiextensionsv1.ClusterScoped
|
clusterScoped := crd.Spec.Scope == apiextensionsv1.ClusterScoped
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ type CustomResourceStorage struct {
|
|||||||
Scale *ScaleREST
|
Scale *ScaleREST
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorage(resource schema.GroupResource, singularResource schema.GroupResource, kind, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor, replicasPathMapping managedfields.ResourcePathMappings) CustomResourceStorage {
|
func NewStorage(resource schema.GroupResource, singularResource schema.GroupResource, kind, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor, replicasPathMapping managedfields.ResourcePathMappings) (CustomResourceStorage, error) {
|
||||||
var storage CustomResourceStorage
|
var storage CustomResourceStorage
|
||||||
store := &genericregistry.Store{
|
store := &genericregistry.Store{
|
||||||
NewFunc: func() runtime.Object {
|
NewFunc: func() runtime.Object {
|
||||||
@ -69,7 +69,7 @@ func NewStorage(resource schema.GroupResource, singularResource schema.GroupReso
|
|||||||
}
|
}
|
||||||
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: strategy.GetAttrs}
|
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: strategy.GetAttrs}
|
||||||
if err := store.CompleteWithOptions(options); err != nil {
|
if err := store.CompleteWithOptions(options); err != nil {
|
||||||
panic(err) // TODO: Propagate error up
|
return storage, fmt.Errorf("failed to update store with options: %w", err)
|
||||||
}
|
}
|
||||||
storage.CustomResource = &REST{store, categories}
|
storage.CustomResource = &REST{store, categories}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func NewStorage(resource schema.GroupResource, singularResource schema.GroupReso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return storage
|
return storage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// REST implements a RESTStorage for API services against etcd
|
// REST implements a RESTStorage for API services against etcd
|
||||||
|
@ -92,7 +92,7 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcd3testi
|
|||||||
}
|
}
|
||||||
table, _ := tableconvertor.New(headers)
|
table, _ := tableconvertor.New(headers)
|
||||||
|
|
||||||
storage := customresource.NewStorage(
|
storage, err := customresource.NewStorage(
|
||||||
groupResource,
|
groupResource,
|
||||||
groupResource,
|
groupResource,
|
||||||
kind,
|
kind,
|
||||||
@ -113,6 +113,9 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcd3testi
|
|||||||
table,
|
table,
|
||||||
managedfields.ResourcePathMappings{},
|
managedfields.ResourcePathMappings{},
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return storage, server
|
return storage, server
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user