mirror of
https://github.com/rancher/rke.git
synced 2025-09-17 07:30:01 +00:00
Add retry to TCP port check
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
@@ -529,7 +530,7 @@ func (c *Cluster) runServicePortChecks(ctx context.Context) error {
|
|||||||
|
|
||||||
func checkPlaneTCPPortsFromHost(ctx context.Context, host *hosts.Host, portList []string, planeHosts []*hosts.Host, image string, prsMap map[string]v3.PrivateRegistry) error {
|
func checkPlaneTCPPortsFromHost(ctx context.Context, host *hosts.Host, portList []string, planeHosts []*hosts.Host, image string, prsMap map[string]v3.PrivateRegistry) error {
|
||||||
var hosts []string
|
var hosts []string
|
||||||
|
var portCheckLogs string
|
||||||
for _, host := range planeHosts {
|
for _, host := range planeHosts {
|
||||||
hosts = append(hosts, host.InternalAddress)
|
hosts = append(hosts, host.InternalAddress)
|
||||||
}
|
}
|
||||||
@@ -551,6 +552,8 @@ func checkPlaneTCPPortsFromHost(ctx context.Context, host *hosts.Host, portList
|
|||||||
Type: "json-file",
|
Type: "json-file",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
for retries := 0; retries < 3; retries++ {
|
||||||
|
logrus.Infof("[network] Checking if host [%s] can connect to host(s) [%s] on port(s) [%s], try #%d", host.Address, strings.Join(hosts, " "), strings.Join(portList, " "), retries+1)
|
||||||
if err := docker.DoRemoveContainer(ctx, host.DClient, PortCheckContainer, host.Address); err != nil {
|
if err := docker.DoRemoveContainer(ctx, host.DClient, PortCheckContainer, host.Address); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -568,11 +571,13 @@ func checkPlaneTCPPortsFromHost(ctx context.Context, host *hosts.Host, portList
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Debugf("[network] Length of containerLog is [%d] on host: %s", len(containerLog), host.Address)
|
logrus.Debugf("[network] Length of containerLog is [%d] on host: %s", len(containerLog), host.Address)
|
||||||
if len(containerLog) > 0 {
|
if len(containerLog) == 0 {
|
||||||
portCheckLogs := strings.Join(strings.Split(strings.TrimSpace(containerLog), "\n"), ", ")
|
|
||||||
return fmt.Errorf("[network] Host [%s] is not able to connect to the following ports: [%s]. Please check network policies and firewall rules", host.Address, portCheckLogs)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
portCheckLogs = strings.Join(strings.Split(strings.TrimSpace(containerLog), "\n"), ", ")
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("[network] Host [%s] is not able to connect to the following ports: [%s]. Please check network policies and firewall rules", host.Address, portCheckLogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPortBindings(hostAddress string, portList []string) []nat.PortBinding {
|
func getPortBindings(hostAddress string, portList []string) []nat.PortBinding {
|
||||||
|
Reference in New Issue
Block a user