Allow clients to determine the difference between create or update on PUT

PUT allows an object to be created (http 201).  This allows REST code to
indicate an object has been created and clients to react to it.

APIServer now deals with <-chan RESTResult instead of <-chan runtime.Object,
allowing more data to be passed through.
This commit is contained in:
Clayton Coleman
2014-10-24 13:16:02 -04:00
parent 2bbd11eda6
commit d5ee171410
25 changed files with 297 additions and 87 deletions

View File

@@ -51,7 +51,7 @@ func (*REST) Get(ctx api.Context, id string) (runtime.Object, error) {
}
// Delete returns an error because bindings are write-only objects.
func (*REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
func (*REST) Delete(ctx api.Context, id string) (<-chan apiserver.RESTResult, error) {
return nil, errors.NewNotFound("binding", id)
}
@@ -61,7 +61,7 @@ func (*REST) New() runtime.Object {
}
// Create attempts to make the assignment indicated by the binding it recieves.
func (b *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
func (b *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
binding, ok := obj.(*api.Binding)
if !ok {
return nil, fmt.Errorf("incorrect type: %#v", obj)
@@ -75,6 +75,6 @@ func (b *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Objec
}
// Update returns an error-- this object may not be updated.
func (b *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
func (b *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
return nil, fmt.Errorf("Bindings may not be changed.")
}

View File

@@ -111,7 +111,7 @@ func TestRESTPost(t *testing.T) {
Message: item.err.Error(),
}
}
if e, a := expect, <-resultChan; !reflect.DeepEqual(e, a) {
if e, a := expect, (<-resultChan).Object; !reflect.DeepEqual(e, a) {
t.Errorf("%v: expected %#v, got %#v", i, e, a)
}
}