RESTStorage should not need to know about async behavior
Also make sure all POST operations return 201 by default. Removes the remainder of the asych logic in RESTStorage and leaves it up to the API server to expose that behavior.
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -44,7 +43,7 @@ func NewREST(registry generic.Registry) *REST {
|
||||
}
|
||||
|
||||
// Create a ResourceQuota object
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
resourceQuota, ok := obj.(*api.ResourceQuota)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
@@ -66,29 +65,27 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
||||
}
|
||||
api.FillObjectMetaSystemFields(ctx, &resourceQuota.ObjectMeta)
|
||||
|
||||
return apiserver.MakeAsync(func() (runtime.Object, error) {
|
||||
err := rs.registry.Create(ctx, resourceQuota.Name, resourceQuota)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs.registry.Get(ctx, resourceQuota.Name)
|
||||
}), nil
|
||||
err := rs.registry.Create(ctx, resourceQuota.Name, resourceQuota)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs.registry.Get(ctx, resourceQuota.Name)
|
||||
}
|
||||
|
||||
// Update updates a ResourceQuota object.
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
|
||||
resourceQuota, ok := obj.(*api.ResourceQuota)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
return nil, false, fmt.Errorf("invalid object type")
|
||||
}
|
||||
|
||||
if !api.ValidNamespace(ctx, &resourceQuota.ObjectMeta) {
|
||||
return nil, errors.NewConflict("resourceQuota", resourceQuota.Namespace, fmt.Errorf("ResourceQuota.Namespace does not match the provided context"))
|
||||
return nil, false, errors.NewConflict("resourceQuota", resourceQuota.Namespace, fmt.Errorf("ResourceQuota.Namespace does not match the provided context"))
|
||||
}
|
||||
|
||||
oldObj, err := rs.registry.Get(ctx, resourceQuota.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
editResourceQuota := oldObj.(*api.ResourceQuota)
|
||||
@@ -100,20 +97,18 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
||||
editResourceQuota.Spec = resourceQuota.Spec
|
||||
|
||||
if errs := validation.ValidateResourceQuota(editResourceQuota); len(errs) > 0 {
|
||||
return nil, errors.NewInvalid("resourceQuota", editResourceQuota.Name, errs)
|
||||
return nil, false, errors.NewInvalid("resourceQuota", editResourceQuota.Name, errs)
|
||||
}
|
||||
|
||||
return apiserver.MakeAsync(func() (runtime.Object, error) {
|
||||
err := rs.registry.Update(ctx, editResourceQuota.Name, editResourceQuota)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs.registry.Get(ctx, editResourceQuota.Name)
|
||||
}), nil
|
||||
if err := rs.registry.Update(ctx, editResourceQuota.Name, editResourceQuota); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
out, err := rs.registry.Get(ctx, editResourceQuota.Name)
|
||||
return out, false, err
|
||||
}
|
||||
|
||||
// Delete deletes the ResourceQuota with the specified name
|
||||
func (rs *REST) Delete(ctx api.Context, name string) (<-chan apiserver.RESTResult, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
|
||||
obj, err := rs.registry.Get(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -122,9 +117,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (<-chan apiserver.RESTResul
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
}
|
||||
return apiserver.MakeAsync(func() (runtime.Object, error) {
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, name)
|
||||
}), nil
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, name)
|
||||
}
|
||||
|
||||
// Get gets a ResourceQuota with the specified name
|
||||
|
Reference in New Issue
Block a user