mirror of https://github.com/k3s-io/k3s
Fix issue with RKE2 servers hanging on listing apiserver addresses
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/5460/head
parent
5b2c14b123
commit
7e447692c5
|
@ -16,6 +16,7 @@ type Proxy interface {
|
|||
Update(addresses []string)
|
||||
SetAPIServerPort(ctx context.Context, port int, isIPv6 bool) error
|
||||
SetSupervisorDefault(address string)
|
||||
IsSupervisorLBEnabled() bool
|
||||
SupervisorURL() string
|
||||
SupervisorAddresses() []string
|
||||
APIServerURL() string
|
||||
|
@ -158,6 +159,10 @@ func (p *proxy) SetSupervisorDefault(address string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *proxy) IsSupervisorLBEnabled() bool {
|
||||
return p.supervisorLB != nil
|
||||
}
|
||||
|
||||
func (p *proxy) SupervisorURL() string {
|
||||
return p.supervisorURL
|
||||
}
|
||||
|
|
|
@ -54,17 +54,23 @@ func Setup(ctx context.Context, config *config.Node, proxy proxy.Proxy) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Try to get a list of apiservers from the server we're connecting to. If that fails, fall back to
|
||||
// querying the endpoints list from Kubernetes. This fallback requires that the server we're joining be
|
||||
// running an apiserver, but is the only safe thing to do if its supervisor is down-level and can't provide us
|
||||
// with an endpoint list.
|
||||
if addresses := agentconfig.APIServers(ctx, config, proxy); len(addresses) > 0 {
|
||||
proxy.SetSupervisorDefault(addresses[0])
|
||||
proxy.Update(addresses)
|
||||
} else {
|
||||
if endpoint, _ := client.CoreV1().Endpoints("default").Get(ctx, "kubernetes", metav1.GetOptions{}); endpoint != nil {
|
||||
if addresses := util.GetAddresses(endpoint); len(addresses) > 0 {
|
||||
proxy.Update(addresses)
|
||||
// The loadbalancer is only disabled when there is a local apiserver. Servers without a local
|
||||
// apiserver load-balance to themselves initially, then switch over to an apiserver node as soon
|
||||
// as we get some addresses from the code below.
|
||||
if proxy.IsSupervisorLBEnabled() && proxy.SupervisorURL() != "" {
|
||||
logrus.Info("Getting list of apiserver endpoints from server")
|
||||
// If not running an apiserver locally, try to get a list of apiservers from the server we're
|
||||
// connecting to. If that fails, fall back to querying the endpoints list from Kubernetes. This
|
||||
// fallback requires that the server we're joining be running an apiserver, but is the only safe
|
||||
// thing to do if its supervisor is down-level and can't provide us with an endpoint list.
|
||||
if addresses := agentconfig.APIServers(ctx, config, proxy); len(addresses) > 0 {
|
||||
proxy.SetSupervisorDefault(addresses[0])
|
||||
proxy.Update(addresses)
|
||||
} else {
|
||||
if endpoint, _ := client.CoreV1().Endpoints("default").Get(ctx, "kubernetes", metav1.GetOptions{}); endpoint != nil {
|
||||
if addresses := util.GetAddresses(endpoint); len(addresses) > 0 {
|
||||
proxy.Update(addresses)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue