Skip to content

Commit

Permalink
enhancement: check default route during installation
Browse files Browse the repository at this point in the history
RKE2 requires a default route to work which is required during
installation. The gateway setting will be checked in Static IP
mode, but it could be absent in DHCP mode.

Check the existence of the default route after applying network
settings and stop the installation if no default route found. The
check will be applied in both ISO and iPXE installation.

Link: harvester/harvester#5675
Signed-off-by: Chris Chiu <[email protected]>
  • Loading branch information
mingshuoqiu authored and mschiu77 committed May 8, 2024
1 parent c8ffa53 commit 7fe14a4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,15 @@ func addNetworkPanel(c *Console) error {
mgmtNetwork.Gateway = ""
mgmtNetwork.MTU = 0
}

isDefaultRouteExist, err := checkDefaultRoute()
if err != nil {
return fmt.Sprintf("Failed to check default route: %s.", err.Error()), nil
}
if !isDefaultRouteExist {
return "No default route found. Please check the router setting on the DHCP server.", nil
}

return "", nil
}

Expand Down Expand Up @@ -2103,6 +2112,18 @@ func addInstallPanel(c *Console) error {
}
}

isDefaultRouteExist, err := checkDefaultRoute()
if err != nil {
logrus.Error(err)
printToPanel(c.Gui, "Failed to check default route.", installPanel)
return
}
if !isDefaultRouteExist {
logrus.Error("No default route found. Please check the router setting on the DHCP server.")
printToPanel(c.Gui, "No default route found. Please check the router setting on the DHCP server.", installPanel)
return
}

// We need ForceGPT because cOS only supports ForceGPT (--force-gpt) flag, not ForceMBR!
c.config.ForceGPT = !c.config.ForceMBR

Expand Down
19 changes: 19 additions & 0 deletions pkg/console/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"syscall"

yipSchema "github.com/mudler/yip/pkg/schema"
"github.com/sirupsen/logrus"
Expand All @@ -16,6 +17,24 @@ import (
"github.com/harvester/harvester-installer/pkg/config"
)

func checkDefaultRoute() (bool, error) {
routes, err := netlink.RouteList(nil, syscall.AF_INET)
if err != nil {
logrus.Errorf("Failed to list routes: %s", err.Error())
return false, err
}

defaultRouteExists := false
for _, route := range routes {
if route.Dst == nil {
defaultRouteExists = true
break
}
}

return defaultRouteExists, nil
}

func applyNetworks(network config.Network, hostname string) ([]byte, error) {
if err := config.RestoreOriginalNetworkConfig(); err != nil {
return nil, err
Expand Down

0 comments on commit 7fe14a4

Please sign in to comment.