From 65c381bfdb60598bb68d694a640830b922f5d511 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 25 Nov 2015 14:33:40 +0100 Subject: [PATCH] Hide internal etcd errors. --- pkg/storage/etcd/util/etcd_util.go | 29 ++++++++++++++++++++----- pkg/storage/etcd/util/etcd_util_test.go | 6 +---- pkg/tools/interfaces.go | 18 --------------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/pkg/storage/etcd/util/etcd_util.go b/pkg/storage/etcd/util/etcd_util.go index d4cebf26bd8..fb990fe91db 100644 --- a/pkg/storage/etcd/util/etcd_util.go +++ b/pkg/storage/etcd/util/etcd_util.go @@ -23,32 +23,49 @@ import ( "net/http" goetcd "github.com/coreos/go-etcd/etcd" - "k8s.io/kubernetes/pkg/tools" +) + +const ( + etcdErrorCodeNotFound = 100 + etcdErrorCodeTestFailed = 101 + etcdErrorCodeNodeExist = 105 + etcdErrorCodeValueRequired = 200 + etcdErrorCodeWatchExpired = 401 + etcdErrorCodeUnreachable = 501 +) + +var ( + etcdErrorNotFound = &goetcd.EtcdError{ErrorCode: etcdErrorCodeNotFound} + etcdErrorTestFailed = &goetcd.EtcdError{ErrorCode: etcdErrorCodeTestFailed} + etcdErrorNodeExist = &goetcd.EtcdError{ErrorCode: etcdErrorCodeNodeExist} + etcdErrorValueRequired = &goetcd.EtcdError{ErrorCode: etcdErrorCodeValueRequired} + etcdErrorWatchExpired = &goetcd.EtcdError{ErrorCode: etcdErrorCodeWatchExpired} + etcdErrorUnreachable = &goetcd.EtcdError{ErrorCode: etcdErrorCodeUnreachable} ) // IsEtcdNotFound returns true if and only if err is an etcd not found error. func IsEtcdNotFound(err error) bool { - return isEtcdErrorNum(err, tools.EtcdErrorCodeNotFound) + return isEtcdErrorNum(err, etcdErrorCodeNotFound) } // IsEtcdNodeExist returns true if and only if err is an etcd node already exist error. func IsEtcdNodeExist(err error) bool { - return isEtcdErrorNum(err, tools.EtcdErrorCodeNodeExist) + return isEtcdErrorNum(err, etcdErrorCodeNodeExist) } // IsEtcdTestFailed returns true if and only if err is an etcd write conflict. func IsEtcdTestFailed(err error) bool { - return isEtcdErrorNum(err, tools.EtcdErrorCodeTestFailed) + return isEtcdErrorNum(err, etcdErrorCodeTestFailed) } // IsEtcdWatchExpired returns true if and only if err indicates the watch has expired. func IsEtcdWatchExpired(err error) bool { - return isEtcdErrorNum(err, tools.EtcdErrorCodeWatchExpired) + return isEtcdErrorNum(err, etcdErrorCodeWatchExpired) } // IsEtcdUnreachable returns true if and only if err indicates the server could not be reached. func IsEtcdUnreachable(err error) bool { - return isEtcdErrorNum(err, tools.EtcdErrorCodeUnreachable) + return isEtcdErrorNum(err, etcdErrorCodeUnreachable) } // isEtcdErrorNum returns true if and only if err is an etcd error, whose errorCode matches errorCode diff --git a/pkg/storage/etcd/util/etcd_util_test.go b/pkg/storage/etcd/util/etcd_util_test.go index 86f50784b3a..09de6aa87c3 100644 --- a/pkg/storage/etcd/util/etcd_util_test.go +++ b/pkg/storage/etcd/util/etcd_util_test.go @@ -28,10 +28,6 @@ import ( "github.com/coreos/go-etcd/etcd" "github.com/stretchr/testify/assert" - - // TODO: once fakeClient has been purged move utils - // and eliminate these deps - "k8s.io/kubernetes/pkg/tools" ) const validEtcdVersion = "etcd 2.0.9" @@ -42,7 +38,7 @@ func TestIsEtcdNotFound(t *testing.T) { t.Errorf("Expected %#v to return %v, but it did not", err, isNotFound) } } - try(tools.EtcdErrorNotFound, true) + try(etcdErrorNotFound, true) try(&etcd.EtcdError{ErrorCode: 101}, false) try(nil, false) try(fmt.Errorf("some other kind of error"), false) diff --git a/pkg/tools/interfaces.go b/pkg/tools/interfaces.go index 5898bfab135..397d269a794 100644 --- a/pkg/tools/interfaces.go +++ b/pkg/tools/interfaces.go @@ -20,24 +20,6 @@ import ( "github.com/coreos/go-etcd/etcd" ) -const ( - EtcdErrorCodeNotFound = 100 - EtcdErrorCodeTestFailed = 101 - EtcdErrorCodeNodeExist = 105 - EtcdErrorCodeValueRequired = 200 - EtcdErrorCodeWatchExpired = 401 - EtcdErrorCodeUnreachable = 501 -) - -var ( - EtcdErrorNotFound = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNotFound} - EtcdErrorTestFailed = &etcd.EtcdError{ErrorCode: EtcdErrorCodeTestFailed} - EtcdErrorNodeExist = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNodeExist} - EtcdErrorValueRequired = &etcd.EtcdError{ErrorCode: EtcdErrorCodeValueRequired} - EtcdErrorWatchExpired = &etcd.EtcdError{ErrorCode: EtcdErrorCodeWatchExpired} - EtcdErrorUnreachable = &etcd.EtcdError{ErrorCode: EtcdErrorCodeUnreachable} -) - // EtcdClient is an injectable interface for testing. type EtcdClient interface { GetCluster() []string