2014-09-05 15:30:35 -04:00
|
|
|
/*
|
2015-05-01 12:19:44 -04:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-09-05 15:30:35 -04:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package etcd
|
|
|
|
|
|
|
|
|
|
import (
|
2015-08-05 18:03:47 -04:00
|
|
|
"k8s.io/kubernetes/pkg/api/errors"
|
2015-12-10 13:32:29 -05:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-12-03 11:09:45 -05:00
|
|
|
"k8s.io/kubernetes/pkg/storage"
|
2014-09-05 15:30:35 -04:00
|
|
|
)
|
|
|
|
|
|
2015-12-03 11:09:45 -05:00
|
|
|
// InterpretListError converts a generic error on a retrieval
|
2015-11-04 15:15:01 -05:00
|
|
|
// operation into the appropriate API error.
|
2015-12-10 13:32:29 -05:00
|
|
|
func InterpretListError(err error, qualifiedResource unversioned.GroupResource) error {
|
2015-11-04 15:15:01 -05:00
|
|
|
switch {
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsNotFound(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewNotFound(qualifiedResource, "")
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsUnreachable(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewServerTimeout(qualifiedResource, "list", 2) // TODO: make configurable or handled at a higher level
|
2015-11-04 15:15:01 -05:00
|
|
|
default:
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 11:09:45 -05:00
|
|
|
// InterpretGetError converts a generic error on a retrieval
|
2014-09-05 15:30:35 -04:00
|
|
|
// operation into the appropriate API error.
|
2015-12-10 13:32:29 -05:00
|
|
|
func InterpretGetError(err error, qualifiedResource unversioned.GroupResource, name string) error {
|
2014-09-05 15:30:35 -04:00
|
|
|
switch {
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsNotFound(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewNotFound(qualifiedResource, name)
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsUnreachable(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewServerTimeout(qualifiedResource, "get", 2) // TODO: make configurable or handled at a higher level
|
2015-06-22 21:19:18 -04:00
|
|
|
default:
|
2015-07-01 14:07:18 -04:00
|
|
|
return err
|
2014-09-05 15:30:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 11:09:45 -05:00
|
|
|
// InterpretCreateError converts a generic error on a create
|
2014-09-05 15:30:35 -04:00
|
|
|
// operation into the appropriate API error.
|
2015-12-10 13:32:29 -05:00
|
|
|
func InterpretCreateError(err error, qualifiedResource unversioned.GroupResource, name string) error {
|
2014-09-05 15:30:35 -04:00
|
|
|
switch {
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsNodeExist(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewAlreadyExists(qualifiedResource, name)
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsUnreachable(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewServerTimeout(qualifiedResource, "create", 2) // TODO: make configurable or handled at a higher level
|
2015-06-22 21:19:18 -04:00
|
|
|
default:
|
2015-07-01 14:07:18 -04:00
|
|
|
return err
|
2014-09-05 15:30:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 11:09:45 -05:00
|
|
|
// InterpretUpdateError converts a generic error on a update
|
2014-09-05 15:30:35 -04:00
|
|
|
// operation into the appropriate API error.
|
2015-12-10 13:32:29 -05:00
|
|
|
func InterpretUpdateError(err error, qualifiedResource unversioned.GroupResource, name string) error {
|
2014-09-05 15:30:35 -04:00
|
|
|
switch {
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsTestFailed(err), storage.IsNodeExist(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewConflict(qualifiedResource, name, err)
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsUnreachable(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewServerTimeout(qualifiedResource, "update", 2) // TODO: make configurable or handled at a higher level
|
2015-06-22 21:19:18 -04:00
|
|
|
default:
|
2015-07-01 14:07:18 -04:00
|
|
|
return err
|
2014-09-05 15:30:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 11:09:45 -05:00
|
|
|
// InterpretDeleteError converts a generic error on a delete
|
2014-09-05 15:30:35 -04:00
|
|
|
// operation into the appropriate API error.
|
2015-12-10 13:32:29 -05:00
|
|
|
func InterpretDeleteError(err error, qualifiedResource unversioned.GroupResource, name string) error {
|
2014-09-05 15:30:35 -04:00
|
|
|
switch {
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsNotFound(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewNotFound(qualifiedResource, name)
|
2015-12-03 11:09:45 -05:00
|
|
|
case storage.IsUnreachable(err):
|
2015-12-10 13:32:29 -05:00
|
|
|
return errors.NewServerTimeout(qualifiedResource, "delete", 2) // TODO: make configurable or handled at a higher level
|
2015-06-22 21:19:18 -04:00
|
|
|
default:
|
2015-07-01 14:07:18 -04:00
|
|
|
return err
|
2014-09-05 15:30:35 -04:00
|
|
|
}
|
|
|
|
|
}
|