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

@@ -45,7 +45,7 @@ func NewREST(m Registry) *REST {
var ErrDoesNotExist = errors.New("The requested resource does not exist.")
var ErrNotHealty = errors.New("The requested minion is not healthy.")
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
minion, ok := obj.(*api.Minion)
if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj)
@@ -72,7 +72,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje
}), nil
}
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(ctx api.Context, id string) (<-chan apiserver.RESTResult, error) {
minion, err := rs.registry.GetMinion(ctx, id)
if minion == nil {
return nil, ErrDoesNotExist
@@ -101,7 +101,7 @@ func (rs *REST) New() runtime.Object {
return &api.Minion{}
}
func (rs *REST) Update(ctx api.Context, minion runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(ctx api.Context, minion runtime.Object) (<-chan apiserver.RESTResult, error) {
return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.")
}

View File

@@ -42,7 +42,7 @@ func TestMinionREST(t *testing.T) {
t.Errorf("insert failed")
}
obj := <-c
if m, ok := obj.(*api.Minion); !ok || m.Name != "baz" {
if m, ok := obj.Object.(*api.Minion); !ok || m.Name != "baz" {
t.Errorf("insert return value was weird: %#v", obj)
}
if obj, err := ms.Get(ctx, "baz"); err != nil || obj.(*api.Minion).Name != "baz" {
@@ -54,7 +54,7 @@ func TestMinionREST(t *testing.T) {
t.Errorf("delete failed")
}
obj = <-c
if s, ok := obj.(*api.Status); !ok || s.Status != api.StatusSuccess {
if s, ok := obj.Object.(*api.Status); !ok || s.Status != api.StatusSuccess {
t.Errorf("delete return value was weird: %#v", obj)
}
if _, err := ms.Get(ctx, "bar"); err != ErrDoesNotExist {