From ea627f987507de38dfc46ab2d9c924690eba5ee9 Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Thu, 15 Mar 2018 10:04:40 +0800 Subject: [PATCH 1/2] check etcd servers by a random order --- .../apiserver/pkg/storage/etcd3/preflight/checks.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go index 899a6fa89c4..220bf0a1c67 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go @@ -18,6 +18,7 @@ package preflight import ( "fmt" + "math/rand" "net" "net/url" "time" @@ -59,9 +60,11 @@ func parseServerURI(serverURI string) (*url.URL, error) { // CheckEtcdServers will attempt to reach all etcd servers once. If any // can be reached, return true. func (con EtcdConnection) CheckEtcdServers() (done bool, err error) { - // Attempt to reach every Etcd server in order - for _, serverURI := range con.ServerList { - host, err := parseServerURI(serverURI) + // Attempt to reach every Etcd server randomly. + serverNumber := len(con.ServerList) + serverPerms := rand.Perm(serverNumber) + for _, index := range serverPerms { + host, err := parseServerURI(con.ServerList[index]) if err != nil { return false, err } From fffa40552cc9f6d372607d1ed40a44d97cecb314 Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Tue, 20 Mar 2018 18:50:19 +0800 Subject: [PATCH 2/2] remove unused code --- .../k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go index 220bf0a1c67..9c12c2090da 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/preflight/checks.go @@ -26,12 +26,6 @@ import ( const connectionTimeout = 1 * time.Second -type connection interface { - serverReachable(address string) bool - parseServerList(serverList []string) error - CheckEtcdServers() (bool, error) -} - // EtcdConnection holds the Etcd server list type EtcdConnection struct { ServerList []string