From f67770132dd94de31bf84ba92ee9072f1eb8796c Mon Sep 17 00:00:00 2001 From: danielqsj Date: Tue, 12 Nov 2019 16:26:59 +0800 Subject: [PATCH] unify alias of api errors under pkg and staging Kubernetes-commit: 5bc0e26c1902e7e28abfc828de19a2dbb3e492c2 --- tools/cache/reflector.go | 12 ++++++------ tools/cache/reflector_test.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/cache/reflector.go b/tools/cache/reflector.go index 1165c523..fc785c2c 100644 --- a/tools/cache/reflector.go +++ b/tools/cache/reflector.go @@ -26,7 +26,7 @@ import ( "sync" "time" - apierrs "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" @@ -375,7 +375,7 @@ loop: break loop } if event.Type == watch.Error { - return apierrs.FromObject(event.Object) + return apierrors.FromObject(event.Object) } if r.expectedType != nil { if e, a := r.expectedType, reflect.TypeOf(event.Object); e != a { @@ -479,9 +479,9 @@ func (r *Reflector) setIsLastSyncResourceVersionExpired(isExpired bool) { } func isExpiredError(err error) bool { - // In Kubernetes 1.17 and earlier, the api server returns both apierrs.StatusReasonExpired and - // apierrs.StatusReasonGone for HTTP 410 (Gone) status code responses. In 1.18 the kube server is more consistent - // and always returns apierrs.StatusReasonExpired. For backward compatibility we can only remove the apierrs.IsGone + // In Kubernetes 1.17 and earlier, the api server returns both apierrors.StatusReasonExpired and + // apierrors.StatusReasonGone for HTTP 410 (Gone) status code responses. In 1.18 the kube server is more consistent + // and always returns apierrors.StatusReasonExpired. For backward compatibility we can only remove the apierrors.IsGone // check when we fully drop support for Kubernetes 1.17 servers from reflectors. - return apierrs.IsResourceExpired(err) || apierrs.IsGone(err) + return apierrors.IsResourceExpired(err) || apierrors.IsGone(err) } diff --git a/tools/cache/reflector_test.go b/tools/cache/reflector_test.go index 2b0796c6..9f6aaa07 100644 --- a/tools/cache/reflector_test.go +++ b/tools/cache/reflector_test.go @@ -26,7 +26,7 @@ import ( "time" "k8s.io/api/core/v1" - apierrs "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -520,7 +520,7 @@ func TestReflectorExpiredExactResourceVersion(t *testing.T) { return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10"}, Items: pods[0:4]}, nil case "10": // When watch cache is disabled, if the exact ResourceVersion requested is not available, a "Expired" error is returned. - return nil, apierrs.NewResourceExpired("The resourceVersion for the provided watch is too old.") + return nil, apierrors.NewResourceExpired("The resourceVersion for the provided watch is too old.") case "": return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "11"}, Items: pods[0:8]}, nil default: @@ -584,7 +584,7 @@ func TestReflectorFullListIfExpired(t *testing.T) { return &v1.PodList{ListMeta: metav1.ListMeta{Continue: "C1", ResourceVersion: "11"}, Items: pods[0:4]}, nil // second page of the above list case rvContinueLimit("", "C1", 4): - return nil, apierrs.NewResourceExpired("The resourceVersion for the provided watch is too old.") + return nil, apierrors.NewResourceExpired("The resourceVersion for the provided watch is too old.") // rv=10 unlimited list case rvContinueLimit("10", "", 0): return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "11"}, Items: pods[0:8]}, nil