unify alias of api errors under pkg and staging
Kubernetes-commit: 5bc0e26c1902e7e28abfc828de19a2dbb3e492c2
This commit is contained in:
parent
310666179d
commit
76c4ab8bb5
|
|
@ -41,7 +41,7 @@ import (
|
||||||
|
|
||||||
fuzzer "k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
fuzzer "k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||||
metainternalversionscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
|
metainternalversionscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
|
||||||
|
|
@ -2802,7 +2802,7 @@ func TestGetNamespaceSelfLink(t *testing.T) {
|
||||||
func TestGetMissing(t *testing.T) {
|
func TestGetMissing(t *testing.T) {
|
||||||
storage := map[string]rest.Storage{}
|
storage := map[string]rest.Storage{}
|
||||||
simpleStorage := SimpleRESTStorage{
|
simpleStorage := SimpleRESTStorage{
|
||||||
errors: map[string]error{"get": apierrs.NewNotFound(schema.GroupResource{Resource: "simples"}, "id")},
|
errors: map[string]error{"get": apierrors.NewNotFound(schema.GroupResource{Resource: "simples"}, "id")},
|
||||||
}
|
}
|
||||||
storage["simple"] = &simpleStorage
|
storage["simple"] = &simpleStorage
|
||||||
handler := handle(storage)
|
handler := handle(storage)
|
||||||
|
|
@ -2822,7 +2822,7 @@ func TestGetMissing(t *testing.T) {
|
||||||
func TestGetRetryAfter(t *testing.T) {
|
func TestGetRetryAfter(t *testing.T) {
|
||||||
storage := map[string]rest.Storage{}
|
storage := map[string]rest.Storage{}
|
||||||
simpleStorage := SimpleRESTStorage{
|
simpleStorage := SimpleRESTStorage{
|
||||||
errors: map[string]error{"get": apierrs.NewServerTimeout(schema.GroupResource{Resource: "simples"}, "id", 2)},
|
errors: map[string]error{"get": apierrors.NewServerTimeout(schema.GroupResource{Resource: "simples"}, "id", 2)},
|
||||||
}
|
}
|
||||||
storage["simple"] = &simpleStorage
|
storage["simple"] = &simpleStorage
|
||||||
handler := handle(storage)
|
handler := handle(storage)
|
||||||
|
|
@ -2925,7 +2925,7 @@ func TestConnectResponderError(t *testing.T) {
|
||||||
connectStorage := &ConnecterRESTStorage{}
|
connectStorage := &ConnecterRESTStorage{}
|
||||||
connectStorage.handlerFunc = func() http.Handler {
|
connectStorage.handlerFunc = func() http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
connectStorage.receivedResponder.Error(apierrs.NewForbidden(schema.GroupResource{Resource: "simples"}, itemID, errors.New("you are terminated")))
|
connectStorage.receivedResponder.Error(apierrors.NewForbidden(schema.GroupResource{Resource: "simples"}, itemID, errors.New("you are terminated")))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
storage := map[string]rest.Storage{
|
storage := map[string]rest.Storage{
|
||||||
|
|
@ -3271,7 +3271,7 @@ func TestDeleteMissing(t *testing.T) {
|
||||||
storage := map[string]rest.Storage{}
|
storage := map[string]rest.Storage{}
|
||||||
ID := "id"
|
ID := "id"
|
||||||
simpleStorage := SimpleRESTStorage{
|
simpleStorage := SimpleRESTStorage{
|
||||||
errors: map[string]error{"delete": apierrs.NewNotFound(schema.GroupResource{Resource: "simples"}, ID)},
|
errors: map[string]error{"delete": apierrors.NewNotFound(schema.GroupResource{Resource: "simples"}, ID)},
|
||||||
}
|
}
|
||||||
storage["simple"] = &simpleStorage
|
storage["simple"] = &simpleStorage
|
||||||
handler := handle(storage)
|
handler := handle(storage)
|
||||||
|
|
@ -3543,7 +3543,7 @@ func TestUpdateMissing(t *testing.T) {
|
||||||
storage := map[string]rest.Storage{}
|
storage := map[string]rest.Storage{}
|
||||||
ID := "id"
|
ID := "id"
|
||||||
simpleStorage := SimpleRESTStorage{
|
simpleStorage := SimpleRESTStorage{
|
||||||
errors: map[string]error{"update": apierrs.NewNotFound(schema.GroupResource{Resource: "simples"}, ID)},
|
errors: map[string]error{"update": apierrors.NewNotFound(schema.GroupResource{Resource: "simples"}, ID)},
|
||||||
}
|
}
|
||||||
storage["simple"] = &simpleStorage
|
storage["simple"] = &simpleStorage
|
||||||
handler := handle(storage)
|
handler := handle(storage)
|
||||||
|
|
@ -3581,7 +3581,7 @@ func TestCreateNotFound(t *testing.T) {
|
||||||
"simple": &SimpleRESTStorage{
|
"simple": &SimpleRESTStorage{
|
||||||
// storage.Create can fail with not found error in theory.
|
// storage.Create can fail with not found error in theory.
|
||||||
// See http://pr.k8s.io/486#discussion_r15037092.
|
// See http://pr.k8s.io/486#discussion_r15037092.
|
||||||
errors: map[string]error{"create": apierrs.NewNotFound(schema.GroupResource{Resource: "simples"}, "id")},
|
errors: map[string]error{"create": apierrors.NewNotFound(schema.GroupResource{Resource: "simples"}, "id")},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
|
|
@ -4217,7 +4217,7 @@ func expectAPIStatus(t *testing.T, method, url string, data []byte, code int) *m
|
||||||
func TestDelayReturnsError(t *testing.T) {
|
func TestDelayReturnsError(t *testing.T) {
|
||||||
storage := SimpleRESTStorage{
|
storage := SimpleRESTStorage{
|
||||||
injectedFunction: func(obj runtime.Object) (runtime.Object, error) {
|
injectedFunction: func(obj runtime.Object) (runtime.Object, error) {
|
||||||
return nil, apierrs.NewAlreadyExists(schema.GroupResource{Resource: "foos"}, "bar")
|
return nil, apierrors.NewAlreadyExists(schema.GroupResource{Resource: "foos"}, "bar")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
handler := handle(map[string]rest.Storage{"foo": &storage})
|
handler := handle(map[string]rest.Storage{"foo": &storage})
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
kubeerr "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/api/validation/path"
|
"k8s.io/apimachinery/pkg/api/validation/path"
|
||||||
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||||
|
|
@ -220,13 +220,13 @@ func NamespaceKeyFunc(ctx context.Context, prefix string, name string) (string,
|
||||||
key := NamespaceKeyRootFunc(ctx, prefix)
|
key := NamespaceKeyRootFunc(ctx, prefix)
|
||||||
ns, ok := genericapirequest.NamespaceFrom(ctx)
|
ns, ok := genericapirequest.NamespaceFrom(ctx)
|
||||||
if !ok || len(ns) == 0 {
|
if !ok || len(ns) == 0 {
|
||||||
return "", kubeerr.NewBadRequest("Namespace parameter required.")
|
return "", apierrors.NewBadRequest("Namespace parameter required.")
|
||||||
}
|
}
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return "", kubeerr.NewBadRequest("Name parameter required.")
|
return "", apierrors.NewBadRequest("Name parameter required.")
|
||||||
}
|
}
|
||||||
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
|
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
|
||||||
return "", kubeerr.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
|
return "", apierrors.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
|
||||||
}
|
}
|
||||||
key = key + "/" + name
|
key = key + "/" + name
|
||||||
return key, nil
|
return key, nil
|
||||||
|
|
@ -236,10 +236,10 @@ func NamespaceKeyFunc(ctx context.Context, prefix string, name string) (string,
|
||||||
// to a resource relative to the given prefix without a namespace.
|
// to a resource relative to the given prefix without a namespace.
|
||||||
func NoNamespaceKeyFunc(ctx context.Context, prefix string, name string) (string, error) {
|
func NoNamespaceKeyFunc(ctx context.Context, prefix string, name string) (string, error) {
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return "", kubeerr.NewBadRequest("Name parameter required.")
|
return "", apierrors.NewBadRequest("Name parameter required.")
|
||||||
}
|
}
|
||||||
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
|
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
|
||||||
return "", kubeerr.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
|
return "", apierrors.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
|
||||||
}
|
}
|
||||||
key := prefix + "/" + name
|
key := prefix + "/" + name
|
||||||
return key, nil
|
return key, nil
|
||||||
|
|
@ -363,7 +363,7 @@ func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation
|
||||||
if err := e.Storage.Create(ctx, key, obj, out, ttl, dryrun.IsDryRun(options.DryRun)); err != nil {
|
if err := e.Storage.Create(ctx, key, obj, out, ttl, dryrun.IsDryRun(options.DryRun)); err != nil {
|
||||||
err = storeerr.InterpretCreateError(err, qualifiedResource, name)
|
err = storeerr.InterpretCreateError(err, qualifiedResource, name)
|
||||||
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
|
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
|
||||||
if !kubeerr.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if errGet := e.Storage.Get(ctx, key, "", out, false); errGet != nil {
|
if errGet := e.Storage.Get(ctx, key, "", out, false); errGet != nil {
|
||||||
|
|
@ -374,7 +374,7 @@ func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if accessor.GetDeletionTimestamp() != nil {
|
if accessor.GetDeletionTimestamp() != nil {
|
||||||
msg := &err.(*kubeerr.StatusError).ErrStatus.Message
|
msg := &err.(*apierrors.StatusError).ErrStatus.Message
|
||||||
*msg = fmt.Sprintf("object is being deleted: %s", *msg)
|
*msg = fmt.Sprintf("object is being deleted: %s", *msg)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -493,7 +493,7 @@ func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObj
|
||||||
}
|
}
|
||||||
if version == 0 {
|
if version == 0 {
|
||||||
if !e.UpdateStrategy.AllowCreateOnUpdate() && !forceAllowCreate {
|
if !e.UpdateStrategy.AllowCreateOnUpdate() && !forceAllowCreate {
|
||||||
return nil, nil, kubeerr.NewNotFound(qualifiedResource, name)
|
return nil, nil, apierrors.NewNotFound(qualifiedResource, name)
|
||||||
}
|
}
|
||||||
creating = true
|
creating = true
|
||||||
creatingObj = obj
|
creatingObj = obj
|
||||||
|
|
@ -533,10 +533,10 @@ func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObj
|
||||||
// leave the Kind field empty. See the discussion in #18526.
|
// leave the Kind field empty. See the discussion in #18526.
|
||||||
qualifiedKind := schema.GroupKind{Group: qualifiedResource.Group, Kind: qualifiedResource.Resource}
|
qualifiedKind := schema.GroupKind{Group: qualifiedResource.Group, Kind: qualifiedResource.Resource}
|
||||||
fieldErrList := field.ErrorList{field.Invalid(field.NewPath("metadata").Child("resourceVersion"), resourceVersion, "must be specified for an update")}
|
fieldErrList := field.ErrorList{field.Invalid(field.NewPath("metadata").Child("resourceVersion"), resourceVersion, "must be specified for an update")}
|
||||||
return nil, nil, kubeerr.NewInvalid(qualifiedKind, name, fieldErrList)
|
return nil, nil, apierrors.NewInvalid(qualifiedKind, name, fieldErrList)
|
||||||
}
|
}
|
||||||
if resourceVersion != version {
|
if resourceVersion != version {
|
||||||
return nil, nil, kubeerr.NewConflict(qualifiedResource, name, fmt.Errorf(OptimisticLockErrorMsg))
|
return nil, nil, apierrors.NewConflict(qualifiedResource, name, fmt.Errorf(OptimisticLockErrorMsg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := rest.BeforeUpdate(e.UpdateStrategy, ctx, obj, existing); err != nil {
|
if err := rest.BeforeUpdate(e.UpdateStrategy, ctx, obj, existing); err != nil {
|
||||||
|
|
@ -916,7 +916,7 @@ func (e *Store) Delete(ctx context.Context, name string, deleteValidation rest.V
|
||||||
// check if obj has pending finalizers
|
// check if obj has pending finalizers
|
||||||
accessor, err := meta.Accessor(obj)
|
accessor, err := meta.Accessor(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, kubeerr.NewInternalError(err)
|
return nil, false, apierrors.NewInternalError(err)
|
||||||
}
|
}
|
||||||
pendingFinalizers := len(accessor.GetFinalizers()) != 0
|
pendingFinalizers := len(accessor.GetFinalizers()) != 0
|
||||||
var ignoreNotFound bool
|
var ignoreNotFound bool
|
||||||
|
|
@ -1038,7 +1038,7 @@ func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.Vali
|
||||||
errs <- err
|
errs <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, _, err := e.Delete(ctx, accessor.GetName(), deleteValidation, options); err != nil && !kubeerr.IsNotFound(err) {
|
if _, _, err := e.Delete(ctx, accessor.GetName(), deleteValidation, options); err != nil && !apierrors.IsNotFound(err) {
|
||||||
klog.V(4).Infof("Delete %s in DeleteCollection failed: %v", accessor.GetName(), err)
|
klog.V(4).Infof("Delete %s in DeleteCollection failed: %v", accessor.GetName(), err)
|
||||||
errs <- err
|
errs <- err
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/apiserver/pkg/storage"
|
"k8s.io/apiserver/pkg/storage"
|
||||||
|
|
@ -332,10 +332,10 @@ func (wc *watchChan) transform(e *event) (res *watch.Event) {
|
||||||
|
|
||||||
func transformErrorToEvent(err error) *watch.Event {
|
func transformErrorToEvent(err error) *watch.Event {
|
||||||
err = interpretWatchError(err)
|
err = interpretWatchError(err)
|
||||||
if _, ok := err.(apierrs.APIStatus); !ok {
|
if _, ok := err.(apierrors.APIStatus); !ok {
|
||||||
err = apierrs.NewInternalError(err)
|
err = apierrors.NewInternalError(err)
|
||||||
}
|
}
|
||||||
status := err.(apierrs.APIStatus).Status()
|
status := err.(apierrors.APIStatus).Status()
|
||||||
return &watch.Event{
|
return &watch.Event{
|
||||||
Type: watch.Error,
|
Type: watch.Error,
|
||||||
Object: &status,
|
Object: &status,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue