Unverified Commit a0a742c3 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #61210 from hzxuzhonghu/etcd-random-check

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. check etcd servers by a random order **What this PR does / why we need it**: Every time a health check is called on the APIServer via the /healthz endpoint, an etcd healthcheck is performed. Here makes servers check with a random order. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #61180 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents 3e4268f5 fffa4055
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment