Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-52410: Propagate error when creating CustomResourceStorage instead of panicking #2216

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcd3testi
}
table, _ := tableconvertor.New(headers, schema.GroupVersionKind{Group: "mygroup.example.com", Version: "v1beta1", Kind: "NoxuItemList"})

storage := customresource.NewStorage(
storage, err := customresource.NewStorage(
groupResource,
groupResource,
kind,
Expand All @@ -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
}
Expand Down