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

Include the interface name in the error message #8346

Merged
merged 1 commit into from
Sep 25, 2023
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
2 changes: 1 addition & 1 deletion pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
if controlConfig.FlannelBackend != config.FlannelBackendNone && len(envInfo.FlannelIface) > 0 {
flannelIface, err = net.InterfaceByName(envInfo.FlannelIface)
if err != nil {
return nil, errors.Wrapf(err, "unable to find interface")
return nil, errors.Wrapf(err, "unable to find interface %s", envInfo.FlannelIface)
}
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/cli/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func Run(ctx *cli.Context) error {
}

if cmds.AgentConfig.FlannelIface != "" && len(cmds.AgentConfig.NodeIP) == 0 {
cmds.AgentConfig.NodeIP.Set(util.GetIPFromInterface(cmds.AgentConfig.FlannelIface))
ip, err := util.GetIPFromInterface(cmds.AgentConfig.FlannelIface)
if err != nil {
return err
}
cmds.AgentConfig.NodeIP.Set(ip)
}

logrus.Info("Starting " + version.Program + " agent " + ctx.App.Version)
Expand Down
6 changes: 5 additions & 1 deletion pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
}

if cmds.AgentConfig.FlannelIface != "" && len(cmds.AgentConfig.NodeIP) == 0 {
cmds.AgentConfig.NodeIP.Set(util.GetIPFromInterface(cmds.AgentConfig.FlannelIface))
ip, err := util.GetIPFromInterface(cmds.AgentConfig.FlannelIface)
if err != nil {
return err
}
cmds.AgentConfig.NodeIP.Set(ip)
}

if serverConfig.ControlConfig.PrivateIP == "" && len(cmds.AgentConfig.NodeIP) != 0 {
Expand Down
9 changes: 4 additions & 5 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,13 @@ func IPStringToIPNet(address string) (*net.IPNet, error) {
}

// GetIPFromInterface is the public function that returns the IP of an interface
func GetIPFromInterface(ifaceName string) string {
func GetIPFromInterface(ifaceName string) (string, error) {
ip, err := getIPFromInterface(ifaceName)
if err != nil {
logrus.Warn(fmt.Errorf("unable to get global unicast ip from interface name: %w", err))
} else {
logrus.Infof("Found ip %s from iface %s", ip, ifaceName)
return "", fmt.Errorf("interface %s does not have a correct global unicast ip: %w", ifaceName, err)
}
return ip
logrus.Infof("Found ip %s from iface %s", ip, ifaceName)
return ip, nil
}

// getIPFromInterface is the private function that returns de IP of an interface
Expand Down