mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 21:53:52 +00:00
Errors should be part of api/errors, not apiserver
Renames constructor methods to be errors.New<name> which changed a few places.
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
@@ -40,17 +41,17 @@ func NewBindingStorage(bindingRegistry Registry) *BindingStorage {
|
||||
|
||||
// List returns an error because bindings are write-only objects.
|
||||
func (*BindingStorage) List(selector labels.Selector) (interface{}, error) {
|
||||
return nil, apiserver.NewNotFoundErr("binding", "list")
|
||||
return nil, errors.NewNotFound("binding", "list")
|
||||
}
|
||||
|
||||
// Get returns an error because bindings are write-only objects.
|
||||
func (*BindingStorage) Get(id string) (interface{}, error) {
|
||||
return nil, apiserver.NewNotFoundErr("binding", id)
|
||||
return nil, errors.NewNotFound("binding", id)
|
||||
}
|
||||
|
||||
// Delete returns an error because bindings are write-only objects.
|
||||
func (*BindingStorage) Delete(id string) (<-chan interface{}, error) {
|
||||
return nil, apiserver.NewNotFoundErr("binding", id)
|
||||
return nil, errors.NewNotFound("binding", id)
|
||||
}
|
||||
|
||||
// New returns a new binding object fit for having data unmarshalled into it.
|
||||
|
@@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@@ -61,7 +62,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 := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
|
||||
return nil, errors.NewInvalid("replicationController", controller.ID, errs)
|
||||
}
|
||||
|
||||
controller.CreationTimestamp = util.Now()
|
||||
@@ -120,7 +121,7 @@ func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
|
||||
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
||||
}
|
||||
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
|
||||
return nil, errors.NewInvalid("replicationController", controller.ID, errs)
|
||||
}
|
||||
return apiserver.MakeAsync(func() (interface{}, error) {
|
||||
err := rs.registry.UpdateController(*controller)
|
||||
|
@@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -280,7 +280,7 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -310,7 +310,7 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
)
|
||||
@@ -45,13 +45,13 @@ func TestGetEndpoints(t *testing.T) {
|
||||
|
||||
func TestGetEndpointsMissingService(t *testing.T) {
|
||||
registry := ®istrytest.ServiceRegistry{
|
||||
Err: apiserver.NewNotFoundErr("service", "foo"),
|
||||
Err: errors.NewNotFound("service", "foo"),
|
||||
}
|
||||
storage := NewStorage(registry)
|
||||
|
||||
// returns service not found
|
||||
_, err := storage.Get("foo")
|
||||
if !apiserver.IsNotFound(err) || !reflect.DeepEqual(err, apiserver.NewNotFoundErr("service", "foo")) {
|
||||
if !errors.IsNotFound(err) || !reflect.DeepEqual(err, errors.NewNotFound("service", "foo")) {
|
||||
t.Errorf("expected NotFound error, got %#v", err)
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/constraint"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -184,7 +184,7 @@ func (r *Registry) DeletePod(podID string) error {
|
||||
podKey := makePodKey(podID)
|
||||
err := r.ExtractObj(podKey, &pod, false)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return apiserver.NewNotFoundErr("pod", podID)
|
||||
return errors.NewNotFound("pod", podID)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -193,7 +193,7 @@ func (r *Registry) DeletePod(podID string) error {
|
||||
// machine and attempt to put it somewhere.
|
||||
err = r.Delete(podKey, true)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return apiserver.NewNotFoundErr("pod", podID)
|
||||
return errors.NewNotFound("pod", podID)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -249,7 +249,7 @@ func (r *Registry) GetController(controllerID string) (*api.ReplicationControlle
|
||||
key := makeControllerKey(controllerID)
|
||||
err := r.ExtractObj(key, &controller, false)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return nil, apiserver.NewNotFoundErr("replicationController", controllerID)
|
||||
return nil, errors.NewNotFound("replicationController", controllerID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -261,7 +261,7 @@ func (r *Registry) GetController(controllerID string) (*api.ReplicationControlle
|
||||
func (r *Registry) CreateController(controller api.ReplicationController) error {
|
||||
err := r.CreateObj(makeControllerKey(controller.ID), controller)
|
||||
if tools.IsEtcdNodeExist(err) {
|
||||
return apiserver.NewAlreadyExistsErr("replicationController", controller.ID)
|
||||
return errors.NewAlreadyExists("replicationController", controller.ID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func (r *Registry) DeleteController(controllerID string) error {
|
||||
key := makeControllerKey(controllerID)
|
||||
err := r.Delete(key, false)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return apiserver.NewNotFoundErr("replicationController", controllerID)
|
||||
return errors.NewNotFound("replicationController", controllerID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (r *Registry) ListServices() (*api.ServiceList, error) {
|
||||
func (r *Registry) CreateService(svc api.Service) error {
|
||||
err := r.CreateObj(makeServiceKey(svc.ID), svc)
|
||||
if tools.IsEtcdNodeExist(err) {
|
||||
return apiserver.NewAlreadyExistsErr("service", svc.ID)
|
||||
return errors.NewAlreadyExists("service", svc.ID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -307,7 +307,7 @@ func (r *Registry) GetService(name string) (*api.Service, error) {
|
||||
var svc api.Service
|
||||
err := r.ExtractObj(key, &svc, false)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return nil, apiserver.NewNotFoundErr("service", name)
|
||||
return nil, errors.NewNotFound("service", name)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -321,7 +321,7 @@ func (r *Registry) GetEndpoints(name string) (*api.Endpoints, error) {
|
||||
var endpoints api.Endpoints
|
||||
err := r.ExtractObj(key, &endpoints, false)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return nil, apiserver.NewNotFoundErr("endpoints", name)
|
||||
return nil, errors.NewNotFound("endpoints", name)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -338,7 +338,7 @@ func (r *Registry) DeleteService(name string) error {
|
||||
key := makeServiceKey(name)
|
||||
err := r.Delete(key, true)
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return apiserver.NewNotFoundErr("service", name)
|
||||
return errors.NewNotFound("service", name)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -21,8 +21,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -627,7 +627,7 @@ func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
|
||||
ID: "foo",
|
||||
},
|
||||
})
|
||||
if !apiserver.IsAlreadyExists(err) {
|
||||
if !errors.IsAlreadyExists(err) {
|
||||
t.Errorf("expected already exists err, got %#v", err)
|
||||
}
|
||||
}
|
||||
@@ -716,7 +716,7 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
|
||||
err := registry.CreateService(api.Service{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
})
|
||||
if !apiserver.IsAlreadyExists(err) {
|
||||
if !errors.IsAlreadyExists(err) {
|
||||
t.Errorf("expected already exists err, got %#v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
@@ -70,7 +71,7 @@ func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
|
||||
}
|
||||
pod.DesiredState.Manifest.ID = pod.ID
|
||||
if errs := validation.ValidatePod(pod); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
|
||||
return nil, errors.NewInvalid("pod", pod.ID, errs)
|
||||
}
|
||||
|
||||
pod.CreationTimestamp = util.Now()
|
||||
@@ -137,7 +138,7 @@ func (rs RegistryStorage) New() interface{} {
|
||||
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
|
||||
pod := obj.(*api.Pod)
|
||||
if errs := validation.ValidatePod(pod); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
|
||||
return nil, errors.NewInvalid("pod", pod.ID, errs)
|
||||
}
|
||||
return apiserver.MakeAsync(func() (interface{}, error) {
|
||||
if err := rs.registry.UpdatePod(*pod); err != nil {
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
@@ -337,7 +337,7 @@ func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -353,7 +353,7 @@ func TestPodStorageValidatesUpdate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
@@ -51,7 +52,7 @@ func NewRegistryStorage(registry Registry, cloud cloudprovider.Interface, machin
|
||||
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
|
||||
srv := obj.(*api.Service)
|
||||
if errs := validation.ValidateService(srv); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
|
||||
return nil, errors.NewInvalid("service", srv.ID, errs)
|
||||
}
|
||||
|
||||
srv.CreationTimestamp = util.Now()
|
||||
@@ -157,7 +158,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
|
||||
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
|
||||
srv := obj.(*api.Service)
|
||||
if errs := validation.ValidateService(srv); len(errs) > 0 {
|
||||
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
|
||||
return nil, errors.NewInvalid("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/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@@ -79,7 +80,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
if !apiserver.IsInvalid(err) {
|
||||
if !errors.IsInvalid(err) {
|
||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user