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:
Kubernetes Prow Robot 2025-03-06 00:57:46 -08:00 committed by GitHub
commit d6c615dd65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}