mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Merge pull request #130422 from bertinatto/propagate-error-custom-resource-storage-2
Propagate error when creating CustomResourceStorage instead of panic'ing
This commit is contained in:
commit
d6c615dd65
@ -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")
|
||||
}
|
||||
|
||||
storages[v.Name] = customresource.NewStorage(
|
||||
storages[v.Name], err = customresource.NewStorage(
|
||||
resource.GroupResource(),
|
||||
singularResource.GroupResource(),
|
||||
kind,
|
||||
@ -847,6 +847,9 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
||||
table,
|
||||
replicasPathInCustomResource,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clusterScoped := crd.Spec.Scope == apiextensionsv1.ClusterScoped
|
||||
|
||||
|
@ -41,7 +41,7 @@ type CustomResourceStorage struct {
|
||||
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
|
||||
store := &genericregistry.Store{
|
||||
NewFunc: func() runtime.Object {
|
||||
@ -69,7 +69,7 @@ func NewStorage(resource schema.GroupResource, singularResource schema.GroupReso
|
||||
}
|
||||
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: strategy.GetAttrs}
|
||||
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}
|
||||
|
||||
@ -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
|
||||
|
@ -92,7 +92,7 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcd3testi
|
||||
}
|
||||
table, _ := tableconvertor.New(headers)
|
||||
|
||||
storage := customresource.NewStorage(
|
||||
storage, err := customresource.NewStorage(
|
||||
groupResource,
|
||||
groupResource,
|
||||
kind,
|
||||
@ -113,6 +113,9 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcd3testi
|
||||
table,
|
||||
managedfields.ResourcePathMappings{},
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
return storage, server
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user