Commit 05a2ef70 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Fix issue with RKE2 servers hanging on listing apiserver addresses

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