Return validation errors from storage create/update

This commit is contained in:
Clayton Coleman
2014-08-21 20:24:53 -04:00
parent 84db1da42b
commit 52923a1348
9 changed files with 187 additions and 26 deletions

View File

@@ -60,7 +60,7 @@ func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
// Pod Manifest ID should be assigned by the pod API
controller.DesiredState.PodTemplate.DesiredState.Manifest.ID = ""
if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
return nil, fmt.Errorf("Validation errors: %v", errs)
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
}
controller.CreationTimestamp = util.Now()
@@ -117,7 +117,7 @@ func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
return nil, fmt.Errorf("not a replication controller: %#v", obj)
}
if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
return nil, fmt.Errorf("Validation errors: %v", errs)
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {
err := rs.registry.UpdateController(*controller)

View File

@@ -25,6 +25,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
)
@@ -272,8 +273,8 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
if c != nil {
t.Errorf("Expected nil channel")
}
if err == nil {
t.Errorf("Expected to get an error")
if !apiserver.IsInvalid(err) {
t.Errorf("Expected to get an invalid resource error, got %v", err)
}
}
}
@@ -302,8 +303,8 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
if c != nil {
t.Errorf("Expected nil channel")
}
if err == nil {
t.Errorf("Expected to get an error")
if !apiserver.IsInvalid(err) {
t.Errorf("Expected to get an invalid resource error, got %v", err)
}
}
}