mirror of https://github.com/k3s-io/k3s
Hide internal etcd errors.
parent
e95e3dec42
commit
65c381bfdb
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue