From 6a1fb71239b8f747e644677925c76d51ec1ec5ca Mon Sep 17 00:00:00 2001 From: likakuli <1154584512@qq.com> Date: Tue, 20 Aug 2019 12:18:46 +0800 Subject: [PATCH] fixes a bug that connection refused error cannot be recognized correctly Kubernetes-commit: 3cec9098020ecc168573c7ee658282954dac2a2e --- tools/cache/reflector.go | 14 ++++---------- tools/cache/reflector_test.go | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tools/cache/reflector.go b/tools/cache/reflector.go index 4c14aaf7..8abde713 100644 --- a/tools/cache/reflector.go +++ b/tools/cache/reflector.go @@ -22,11 +22,8 @@ import ( "fmt" "io" "math/rand" - "net" - "net/url" "reflect" "sync" - "syscall" "time" apierrs "k8s.io/apimachinery/pkg/api/errors" @@ -35,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/naming" + utilnet "k8s.io/apimachinery/pkg/util/net" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" @@ -285,13 +283,9 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error { // It doesn't make sense to re-list all objects because most likely we will be able to restart // watch where we ended. // If that's the case wait and resend watch request. - if urlError, ok := err.(*url.Error); ok { - if opError, ok := urlError.Err.(*net.OpError); ok { - if errno, ok := opError.Err.(syscall.Errno); ok && errno == syscall.ECONNREFUSED { - time.Sleep(time.Second) - continue - } - } + if utilnet.IsConnectionRefused(err) { + time.Sleep(time.Second) + continue } return nil } diff --git a/tools/cache/reflector_test.go b/tools/cache/reflector_test.go index caa07232..a62638c3 100644 --- a/tools/cache/reflector_test.go +++ b/tools/cache/reflector_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait"