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

@@ -48,7 +48,7 @@ func NewRegistryStorage(registry Registry, cloud cloudprovider.Interface, machin
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
srv := obj.(*api.Service)
if errs := api.ValidateService(srv); len(errs) > 0 {
return nil, fmt.Errorf("Validation errors: %v", errs)
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
}
srv.CreationTimestamp = util.Now()
@@ -147,11 +147,8 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
srv := obj.(*api.Service)
if srv.ID == "" {
return nil, fmt.Errorf("ID should not be empty: %#v", srv)
}
if errs := api.ValidateService(srv); len(errs) > 0 {
return nil, fmt.Errorf("Validation errors: %v", errs)
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {
// TODO: check to see if external load balancer status changed

View File

@@ -21,6 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
@@ -78,8 +79,8 @@ func TestServiceStorageValidatesCreate(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)
}
}
@@ -139,8 +140,8 @@ func TestServiceStorageValidatesUpdate(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)
}
}
}