Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: check default route during installation #725

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
ErrMsgVLANShouldBeANumberInRange string = "VLAN ID should be a number 1 ~ 4094."
ErrMsgMTUShouldBeANumber string = "MTU should be a number."
NtpSettingName string = "ntp-servers"
ErrMsgNoDefaultRoute string = "No default route found. Please check the router setting on the DHCP server."
)

var (
Expand Down Expand Up @@ -1388,6 +1389,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 ErrMsgNoDefaultRoute, nil
}

return "", nil
}

Expand Down Expand Up @@ -2103,6 +2113,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(ErrMsgNoDefaultRoute)
printToPanel(c.Gui, ErrMsgNoDefaultRoute, 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 {
tserong marked this conversation as resolved.
Show resolved Hide resolved
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
Loading