mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
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 ```
This commit is contained in:
commit
a0a742c38b
@ -18,6 +18,7 @@ package preflight
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -25,12 +26,6 @@ import (
|
|||||||
|
|
||||||
const connectionTimeout = 1 * time.Second
|
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
|
// EtcdConnection holds the Etcd server list
|
||||||
type EtcdConnection struct {
|
type EtcdConnection struct {
|
||||||
ServerList []string
|
ServerList []string
|
||||||
@ -59,9 +54,11 @@ func parseServerURI(serverURI string) (*url.URL, error) {
|
|||||||
// CheckEtcdServers will attempt to reach all etcd servers once. If any
|
// CheckEtcdServers will attempt to reach all etcd servers once. If any
|
||||||
// can be reached, return true.
|
// can be reached, return true.
|
||||||
func (con EtcdConnection) CheckEtcdServers() (done bool, err error) {
|
func (con EtcdConnection) CheckEtcdServers() (done bool, err error) {
|
||||||
// Attempt to reach every Etcd server in order
|
// Attempt to reach every Etcd server randomly.
|
||||||
for _, serverURI := range con.ServerList {
|
serverNumber := len(con.ServerList)
|
||||||
host, err := parseServerURI(serverURI)
|
serverPerms := rand.Perm(serverNumber)
|
||||||
|
for _, index := range serverPerms {
|
||||||
|
host, err := parseServerURI(con.ServerList[index])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user