diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 473c631a3feb..8a7a01bf023e 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -363,7 +363,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N if !envInfo.NoFlannel && 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) } } diff --git a/pkg/cli/agent/agent.go b/pkg/cli/agent/agent.go index 60ee1e24d232..c9be20e15327 100644 --- a/pkg/cli/agent/agent.go +++ b/pkg/cli/agent/agent.go @@ -64,7 +64,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) diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index e13f07ba30cb..b145353ed0e2 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -221,7 +221,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 { diff --git a/pkg/util/net.go b/pkg/util/net.go index 913d90736dc6..244b3f64b866 100644 --- a/pkg/util/net.go +++ b/pkg/util/net.go @@ -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