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..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 @@ -18,6 +18,7 @@ package preflight import ( "fmt" + "math/rand" "net" "net/url" "time" @@ -25,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 @@ -59,9 +54,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 }