unify alias of api errors under pkg and staging
Kubernetes-commit: 5bc0e26c1902e7e28abfc828de19a2dbb3e492c2
This commit is contained in:
parent
0a26b53c37
commit
4b914450ab
|
@ -34,7 +34,7 @@ import (
|
|||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
kubeerr "k8s.io/apimachinery/pkg/api/errors"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -651,7 +651,7 @@ func TestApplyRetry(t *testing.T) {
|
|||
case p == pathRC && m == "PATCH":
|
||||
if firstPatch {
|
||||
firstPatch = false
|
||||
statusErr := kubeerr.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
|
||||
statusErr := apierrors.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
|
||||
bodyBytes, _ := json.Marshal(statusErr)
|
||||
bodyErr := ioutil.NopCloser(bytes.NewReader(bodyBytes))
|
||||
return &http.Response{StatusCode: http.StatusConflict, Header: cmdtesting.DefaultHeader(), Body: bodyErr}, nil
|
||||
|
@ -1278,7 +1278,7 @@ func TestForceApply(t *testing.T) {
|
|||
case strings.HasSuffix(p, pathRC) && m == "PATCH":
|
||||
counts["patch"]++
|
||||
if counts["patch"] <= 6 {
|
||||
statusErr := kubeerr.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
|
||||
statusErr := apierrors.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
|
||||
bodyBytes, _ := json.Marshal(statusErr)
|
||||
bodyErr := ioutil.NopCloser(bytes.NewReader(bodyBytes))
|
||||
return &http.Response{StatusCode: http.StatusConflict, Header: cmdtesting.DefaultHeader(), Body: bodyErr}, nil
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
kapierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
@ -483,7 +483,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
|||
Do()
|
||||
|
||||
if o.IgnoreNotFound {
|
||||
r.IgnoreErrors(kapierrors.IsNotFound)
|
||||
r.IgnoreErrors(apierrors.IsNotFound)
|
||||
}
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
jsonpatch "github.com/evanphx/json-patch"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -60,10 +60,10 @@ type debugError interface {
|
|||
// source is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource.
|
||||
func AddSourceToErr(verb string, source string, err error) error {
|
||||
if source != "" {
|
||||
if statusError, ok := err.(kerrors.APIStatus); ok {
|
||||
if statusError, ok := err.(apierrors.APIStatus); ok {
|
||||
status := statusError.Status()
|
||||
status.Message = fmt.Sprintf("error when %s %q: %v", verb, source, status.Message)
|
||||
return &kerrors.StatusError{ErrStatus: status}
|
||||
return &apierrors.StatusError{ErrStatus: status}
|
||||
}
|
||||
return fmt.Errorf("error when %s %q: %v", verb, source, err)
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ func checkErr(err error, handleErr func(string, int)) {
|
|||
switch {
|
||||
case err == ErrExit:
|
||||
handleErr("", DefaultErrorExitCode)
|
||||
case kerrors.IsInvalid(err):
|
||||
details := err.(*kerrors.StatusError).Status().Details
|
||||
case apierrors.IsInvalid(err):
|
||||
details := err.(*apierrors.StatusError).Status().Details
|
||||
s := "The request is invalid"
|
||||
if details == nil {
|
||||
handleErr(s, DefaultErrorExitCode)
|
||||
|
@ -202,7 +202,7 @@ func StandardErrorMessage(err error) (string, bool) {
|
|||
if debugErr, ok := err.(debugError); ok {
|
||||
klog.V(4).Infof(debugErr.DebugError())
|
||||
}
|
||||
status, isStatus := err.(kerrors.APIStatus)
|
||||
status, isStatus := err.(apierrors.APIStatus)
|
||||
switch {
|
||||
case isStatus:
|
||||
switch s := status.Status(); {
|
||||
|
@ -213,7 +213,7 @@ func StandardErrorMessage(err error) (string, bool) {
|
|||
default:
|
||||
return fmt.Sprintf("Error from server: %s", err.Error()), true
|
||||
}
|
||||
case kerrors.IsUnexpectedObjectError(err):
|
||||
case apierrors.IsUnexpectedObjectError(err):
|
||||
return fmt.Sprintf("Server returned an unexpected response: %s", err.Error()), true
|
||||
}
|
||||
switch t := err.(type) {
|
||||
|
@ -259,7 +259,7 @@ func MultilineError(prefix string, err error) string {
|
|||
// Returns true if a case exists to handle the error type, or false otherwise.
|
||||
func PrintErrorWithCauses(err error, errOut io.Writer) bool {
|
||||
switch t := err.(type) {
|
||||
case *kerrors.StatusError:
|
||||
case *apierrors.StatusError:
|
||||
errorDetails := t.Status().Details
|
||||
if errorDetails != nil {
|
||||
fmt.Fprintf(errOut, "error: %s %q is invalid\n\n", errorDetails.Kind, errorDetails.Name)
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"time"
|
||||
|
||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
api "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -58,8 +58,8 @@ var (
|
|||
)
|
||||
|
||||
func TestReplicationControllerScaleRetry(t *testing.T) {
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
}
|
||||
scaleClientExpectedAction := []string{"patch", "get"}
|
||||
scaleClient := createFakeScaleClient("replicationcontrollers", "foo-v1", 2, verbsOnError)
|
||||
|
@ -94,8 +94,8 @@ func TestReplicationControllerScaleRetry(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReplicationControllerScaleInvalid(t *testing.T) {
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
}
|
||||
scaleClientExpectedAction := []string{"patch"}
|
||||
scaleClient := createFakeScaleClient("replicationcontrollers", "foo-v1", 1, verbsOnError)
|
||||
|
@ -168,8 +168,8 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeploymentScaleRetry(t *testing.T) {
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
}
|
||||
scaleClientExpectedAction := []string{"patch", "get"}
|
||||
scaleClient := createFakeScaleClient("deployments", "foo", 2, verbsOnError)
|
||||
|
@ -226,8 +226,8 @@ func TestDeploymentScale(t *testing.T) {
|
|||
|
||||
func TestDeploymentScaleInvalid(t *testing.T) {
|
||||
scaleClientExpectedAction := []string{"patch"}
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
}
|
||||
scaleClient := createFakeScaleClient("deployments", "foo", 2, verbsOnError)
|
||||
scaler := NewScaler(scaleClient)
|
||||
|
@ -299,8 +299,8 @@ func TestStatefulSetScale(t *testing.T) {
|
|||
|
||||
func TestStatefulSetScaleRetry(t *testing.T) {
|
||||
scaleClientExpectedAction := []string{"patch", "get"}
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
}
|
||||
scaleClient := createFakeScaleClient("statefulsets", "foo", 2, verbsOnError)
|
||||
scaler := NewScaler(scaleClient)
|
||||
|
@ -335,8 +335,8 @@ func TestStatefulSetScaleRetry(t *testing.T) {
|
|||
|
||||
func TestStatefulSetScaleInvalid(t *testing.T) {
|
||||
scaleClientExpectedAction := []string{"patch"}
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
}
|
||||
scaleClient := createFakeScaleClient("statefulsets", "foo", 2, verbsOnError)
|
||||
scaler := NewScaler(scaleClient)
|
||||
|
@ -407,8 +407,8 @@ func TestReplicaSetScale(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReplicaSetScaleRetry(t *testing.T) {
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewConflict(api.Resource("Status"), "foo", nil),
|
||||
}
|
||||
scaleClientExpectedAction := []string{"patch", "get"}
|
||||
scaleClient := createFakeScaleClient("replicasets", "foo", 2, verbsOnError)
|
||||
|
@ -443,8 +443,8 @@ func TestReplicaSetScaleRetry(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReplicaSetScaleInvalid(t *testing.T) {
|
||||
verbsOnError := map[string]*kerrors.StatusError{
|
||||
"patch": kerrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
verbsOnError := map[string]*apierrors.StatusError{
|
||||
"patch": apierrors.NewInvalid(api.Kind("Status"), "foo", nil),
|
||||
}
|
||||
scaleClientExpectedAction := []string{"patch"}
|
||||
scaleClient := createFakeScaleClient("replicasets", "foo", 2, verbsOnError)
|
||||
|
@ -688,12 +688,12 @@ func TestGenericScale(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func createFakeScaleClient(resource string, resourceName string, replicas int, errorsOnVerb map[string]*kerrors.StatusError) *fakescale.FakeScaleClient {
|
||||
shouldReturnAnError := func(verb string) (*kerrors.StatusError, bool) {
|
||||
func createFakeScaleClient(resource string, resourceName string, replicas int, errorsOnVerb map[string]*apierrors.StatusError) *fakescale.FakeScaleClient {
|
||||
shouldReturnAnError := func(verb string) (*apierrors.StatusError, bool) {
|
||||
if anError, anErrorExists := errorsOnVerb[verb]; anErrorExists {
|
||||
return anError, true
|
||||
}
|
||||
return &kerrors.StatusError{}, false
|
||||
return &apierrors.StatusError{}, false
|
||||
}
|
||||
newReplicas := int32(replicas)
|
||||
scaleClient := &fakescale.FakeScaleClient{}
|
||||
|
|
Loading…
Reference in New Issue