mirror of
https://github.com/rancher/rke.git
synced 2025-08-10 11:13:44 +00:00
Do preliminary KubeAPI port check using HTTP. Resolves rancher#1256.
This commit is contained in:
parent
c08d7738b2
commit
9c94d6525d
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -291,13 +292,20 @@ func (c *Cluster) CheckClusterPorts(ctx context.Context, currentCluster *Cluster
|
|||||||
func (c *Cluster) checkKubeAPIPort(ctx context.Context) error {
|
func (c *Cluster) checkKubeAPIPort(ctx context.Context) error {
|
||||||
log.Infof(ctx, "[network] Checking KubeAPI port Control Plane hosts")
|
log.Infof(ctx, "[network] Checking KubeAPI port Control Plane hosts")
|
||||||
for _, host := range c.ControlPlaneHosts {
|
for _, host := range c.ControlPlaneHosts {
|
||||||
logrus.Debugf("[network] Checking KubeAPI port [%s] on host: %s", KubeAPIPort, host.Address)
|
logrus.Debugf("[network] TCP dialing KubeAPI port [%s] on host: %s", KubeAPIPort, host.Address)
|
||||||
address := fmt.Sprintf("%s:%s", host.Address, KubeAPIPort)
|
address := fmt.Sprintf("%s:%s", host.Address, KubeAPIPort)
|
||||||
conn, err := net.Dial("tcp", address)
|
tcpConn, err := net.Dial("tcp", address)
|
||||||
|
if err == nil {
|
||||||
|
tcpConn.Close()
|
||||||
|
} else {
|
||||||
|
// Try to connect using HTTP
|
||||||
|
logrus.Debugf("[network] Failed to TCP dial [%s:%s], re-trying with an HTTP client...", host.Address, KubeAPIPort)
|
||||||
|
resp, err := http.Get("http://" + address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("[network] Can't access KubeAPI port [%s] on Control Plane host: %s", KubeAPIPort, host.Address)
|
return fmt.Errorf("[network] Can't access KubeAPI port [%s] on Control Plane host: %s", KubeAPIPort, host.Address)
|
||||||
}
|
}
|
||||||
conn.Close()
|
defer resp.Body.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -345,12 +353,9 @@ func (c *Cluster) deployListener(ctx context.Context, host *hosts.Host, portList
|
|||||||
imageCfg := &container.Config{
|
imageCfg := &container.Config{
|
||||||
Image: c.SystemImages.Alpine,
|
Image: c.SystemImages.Alpine,
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
"nc",
|
"bash",
|
||||||
"-kl",
|
"-c",
|
||||||
"-p",
|
"while true; do { echo -e \"HTTP/1.1 200 OK\" | nc -kl -p 1337; } done",
|
||||||
"1337",
|
|
||||||
"-e",
|
|
||||||
"echo",
|
|
||||||
},
|
},
|
||||||
ExposedPorts: nat.PortSet{
|
ExposedPorts: nat.PortSet{
|
||||||
"1337/tcp": {},
|
"1337/tcp": {},
|
||||||
|
Loading…
Reference in New Issue
Block a user