diff --git a/api/handler/delete.go b/api/handler/delete.go index e64d5a3a..63814cd8 100644 --- a/api/handler/delete.go +++ b/api/handler/delete.go @@ -8,13 +8,20 @@ import ( func DeleteHandler(request *types.APIContext) error { store := request.Schema.Store - if store != nil { - err := store.Delete(request, request.Schema, request.ID) - if err != nil { - return err - } + if store == nil { + request.WriteResponse(http.StatusNoContent, nil) + return nil } - request.WriteResponse(http.StatusNoContent, nil) + obj, err := store.Delete(request, request.Schema, request.ID) + if err != nil { + return err + } + + if obj == nil { + request.WriteResponse(http.StatusNoContent, nil) + } else { + request.WriteResponse(http.StatusOK, obj) + } return nil } diff --git a/store/crd/crd_store.go b/store/crd/crd_store.go index cd8f4df4..d626b95c 100644 --- a/store/crd/crd_store.go +++ b/store/crd/crd_store.go @@ -65,10 +65,10 @@ func (c *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id stri return store.ByID(apiContext, schema, id) } -func (c *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error { +func (c *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { store, ok := c.schemaStores[key(schema)] if !ok { - return nil + return nil, nil } return store.Delete(apiContext, schema, id) } diff --git a/store/empty/empty_store.go b/store/empty/empty_store.go index 12418534..3aaa8cc4 100644 --- a/store/empty/empty_store.go +++ b/store/empty/empty_store.go @@ -7,8 +7,8 @@ import ( type Store struct { } -func (e *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error { - return nil +func (e *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { + return nil, nil } func (e *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { diff --git a/store/proxy/proxy_store.go b/store/proxy/proxy_store.go index 2b119b97..f5b7c478 100644 --- a/store/proxy/proxy_store.go +++ b/store/proxy/proxy_store.go @@ -192,7 +192,7 @@ func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data return result, err } -func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error { +func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { namespace, id := splitID(id) prop := metav1.DeletePropagationForeground @@ -202,7 +202,16 @@ func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id st }). Name(id) - return req.Do().Error() + err := req.Do().Error() + if err != nil { + return nil, err + } + + obj, err := p.ByID(apiContext, schema, id) + if err != nil { + return nil, nil + } + return obj, nil } func (p *Store) singleResult(schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) { diff --git a/store/tranform/transform.go b/store/tranform/transform.go index 76198bed..1f5d06b4 100644 --- a/store/tranform/transform.go +++ b/store/tranform/transform.go @@ -100,6 +100,6 @@ func (t *TransformingStore) Update(apiContext *types.APIContext, schema *types.S return t.Transformer(apiContext, data) } -func (t *TransformingStore) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error { +func (t *TransformingStore) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { return t.Store.Delete(apiContext, schema, id) } diff --git a/store/wrapper/wrapper.go b/store/wrapper/wrapper.go index fd78832d..879278da 100644 --- a/store/wrapper/wrapper.go +++ b/store/wrapper/wrapper.go @@ -90,9 +90,9 @@ func (s *StoreWrapper) Update(apiContext *types.APIContext, schema *types.Schema }, data), nil } -func (s *StoreWrapper) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error { +func (s *StoreWrapper) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) { if err := validateGet(apiContext, schema, id); err != nil { - return err + return nil, err } return s.store.Delete(apiContext, schema, id) diff --git a/types/server_types.go b/types/server_types.go index b52dd5f9..12ad40bc 100644 --- a/types/server_types.go +++ b/types/server_types.go @@ -156,6 +156,6 @@ type Store interface { List(apiContext *APIContext, schema *Schema, opt QueryOptions) ([]map[string]interface{}, error) Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error) Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error) - Delete(apiContext *APIContext, schema *Schema, id string) error + Delete(apiContext *APIContext, schema *Schema, id string) (map[string]interface{}, error) Watch(apiContext *APIContext, schema *Schema, opt QueryOptions) (chan map[string]interface{}, error) }