Skip to content

Commit

Permalink
fix(platform): validate default route hangs (#2098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ryu committed Oct 10, 2022
1 parent f5c03d3 commit 68050dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions pkg/platform/provider/baremetal/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,15 @@ func ValidateSelinux(fldPath *field.Path, sshs []*ssh.SSH) field.ErrorList {
func ValidateDefaultRoute(fldPath *field.Path, sshs []*ssh.SSH, expectedNetInterface string) field.ErrorList {
allErrs := field.ErrorList{}
for i, one := range sshs {
realNetInterface := ssh.GetNetworkInterface(one, one.Host)
if realNetInterface != expectedNetInterface {
defaultRouteIP := ssh.GetDefaultRouteIP(one)
if defaultRouteIP != one.Host {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), one.Host,
fmt.Sprintf("network interface of IP %s is %s not %s", one.Host, realNetInterface, expectedNetInterface)))
fmt.Sprintf("host IP %s is not default route IP %s", one.Host, defaultRouteIP)))
}
realNetInterface = ssh.GetDefaultRouteInterface(one)
if realNetInterface != expectedNetInterface {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), one.Host,
fmt.Sprintf("network interface of default route is %s not %s", realNetInterface, expectedNetInterface)))
defaultRouteInterface := ssh.GetDefaultRouteInterface(one)
if defaultRouteInterface != expectedNetInterface {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), expectedNetInterface,
fmt.Sprintf("%s is not default route interface %s", defaultRouteInterface, expectedNetInterface)))
}
}
return allErrs
Expand Down
9 changes: 8 additions & 1 deletion pkg/util/ssh/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ func GetNetworkInterface(s Interface, ip string) string {

// GetDefaultRouteInterface returns default router network interface
func GetDefaultRouteInterface(s Interface) string {
stdout, _, _, _ := s.Exec("route | grep 'default' |awk '{print $NF}'")
stdout, _, _, _ := s.Exec(`ip route get 1.1.1.1 | grep -oP 'dev \K\S+'`)

return strings.Replace(stdout, "\n", "", -1)
}

// GetDefaultRouteIP returns default router network interface
func GetDefaultRouteIP(s Interface) string {
stdout, _, _, _ := s.Exec(`ip route get 1.1.1.1 | grep -oP 'src \K\S+'`)

return strings.Replace(stdout, "\n", "", -1)
}
Expand Down

0 comments on commit 68050dc

Please sign in to comment.