mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 23:19:26 +00:00
Return validation errors from storage create/update
This commit is contained in:
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user