Skip to content

Commit

Permalink
fix(platform): fix nfs&ceph-fs validate connection timeout (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-chen authored Nov 2, 2022
1 parent 7c220dd commit c7f9641
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pkg/platform/provider/baremetal/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"tkestack.io/tke/pkg/util/log"
utilmath "tkestack.io/tke/pkg/util/math"
"tkestack.io/tke/pkg/util/ssh"
"tkestack.io/tke/pkg/util/validation"
utilvalidation "tkestack.io/tke/pkg/util/validation"
)

Expand Down Expand Up @@ -729,7 +728,7 @@ func ValidateCIDRs(cls *platform.Cluster, specPath *field.Path) field.ErrorList
} else {
checkFunc(fldPath, cidr)
if clusterCIDR != nil && serviceCIDR != nil {
if err := validation.IsSubNetOverlapped(clusterCIDR, serviceCIDR); err != nil {
if err := utilvalidation.IsSubNetOverlapped(clusterCIDR, serviceCIDR); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, cidr, err.Error()))
}
if _, err := ipallocator.GetIndexedIP(serviceCIDR, 10); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/util/ssh/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func OSVersion(s Interface) (os string, err error) {
func ReservePorts(s Interface, ip string, ports []int) (isInused bool, message string, err error) {
var cmd string
for _, port := range ports {
cmd += fmt.Sprintf(`bash -c "</dev/tcp/%s/%d" &>/dev/null; echo $?; `, ip, port)
cmd += fmt.Sprintf(`timeout 3 bash -c "</dev/tcp/%s/%d" &>/dev/null; echo $?; `, ip, port)
}
out, _, _, _ := s.Exec(cmd)
out = strings.TrimSuffix(out, "\n")
Expand All @@ -175,6 +175,10 @@ func ReservePorts(s Interface, ip string, ports []int) (isInused bool, message s
return false, "", fmt.Errorf("check results length does not match need check ports length, get results output is: %s", out)
}
for i, result := range results {
// if return code is 124, it means that the connection is timeout
if result == "124" {
return false, "", fmt.Errorf("connect %s:%d timeout", ip, ports[i])
}
if result != "1" {
message += fmt.Sprintf("%d ", ports[i])
}
Expand Down Expand Up @@ -226,7 +230,7 @@ func SelinuxEnabled(s Interface) (enabled bool, err error) {
}

func CheckNFS(s Interface, server string, path string) (err error) {
_, stderr, exit, err := s.Execf("mkdir -p /tmp/nfs/&& mount -t nfs %s:%s /tmp/nfs/&& umount /tmp/nfs/&& rm -rf /tmp/nfs/", server, path)
_, stderr, exit, err := s.Execf("mkdir -p /tmp/nfs/ && mount -t nfs -o soft,timeo=15,retry=0 %s:%s /tmp/nfs/ && umount /tmp/nfs/ && rm -rf /tmp/nfs/", server, path)
if exit != 0 || err != nil {
return fmt.Errorf("check nfs failed:exit %d:stderr %s:error %s", exit, stderr, err)
}
Expand Down

0 comments on commit c7f9641

Please sign in to comment.