1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-22 16:45:57 +00:00

Reorder etcd servers list

This commit is contained in:
Erik Wilson 2019-05-24 07:49:49 -07:00 committed by Alena Prokharchyk
parent 5962489879
commit 581e3389c4
2 changed files with 19 additions and 8 deletions

View File

@ -100,7 +100,7 @@ func BuildRKEConfigNodePlan(ctx context.Context, myCluster *Cluster, host *hosts
func (c *Cluster) BuildKubeAPIProcess(host *hosts.Host, prefixPath string) v3.Process { func (c *Cluster) BuildKubeAPIProcess(host *hosts.Host, prefixPath string) v3.Process {
// check if external etcd is used // check if external etcd is used
etcdConnectionString := services.GetEtcdConnString(c.EtcdHosts) etcdConnectionString := services.GetEtcdConnString(c.EtcdHosts, host.Address)
etcdPathPrefix := EtcdPathPrefix etcdPathPrefix := EtcdPathPrefix
etcdClientCert := pki.GetCertPath(pki.KubeNodeCertName) etcdClientCert := pki.GetCertPath(pki.KubeNodeCertName)
etcdClientKey := pki.GetKeyPath(pki.KubeNodeCertName) etcdClientKey := pki.GetKeyPath(pki.KubeNodeCertName)

View File

@ -6,8 +6,10 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"net" "net"
"net/http" "net/http"
"strings"
"time" "time"
etcdclient "github.com/coreos/etcd/client" etcdclient "github.com/coreos/etcd/client"
@ -112,15 +114,24 @@ func getEtcdDialer(localConnDialerFactory hosts.DialerFactory, etcdHost *hosts.H
return etcdFactory(etcdHost) return etcdFactory(etcdHost)
} }
func GetEtcdConnString(hosts []*hosts.Host) string { func GetEtcdConnString(hosts []*hosts.Host, hostAddress string) string {
connString := "" connHosts := []string{}
for i, host := range hosts { containsHostAddress := false
connString += "https://" + host.InternalAddress + ":2379" for _, host := range hosts {
if i < (len(hosts) - 1) { if host.InternalAddress == hostAddress {
connString += "," containsHostAddress = true
continue
} }
connHosts = append(connHosts, "https://"+host.InternalAddress+":2379")
} }
return connString rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(connHosts), func(i, j int) {
connHosts[i], connHosts[j] = connHosts[j], connHosts[i]
})
if containsHostAddress {
connHosts = append([]string{"https://" + hostAddress + ":2379"}, connHosts...)
}
return strings.Join(connHosts, ",")
} }
func getEtcdTLSConfig(certificate, key []byte) (*tls.Config, error) { func getEtcdTLSConfig(certificate, key []byte) (*tls.Config, error) {