From 2c39febdd26bac21b2f6013f290b887e9e0b2973 Mon Sep 17 00:00:00 2001 From: Roberto Bonafiglia Date: Mon, 7 Mar 2022 11:05:08 +0100 Subject: [PATCH] Fixed in case of empty address Signed-off-by: Roberto Bonafiglia --- pkg/agent/flannel/flannel.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/agent/flannel/flannel.go b/pkg/agent/flannel/flannel.go index 7a690754ec..a394f241f3 100644 --- a/pkg/agent/flannel/flannel.go +++ b/pkg/agent/flannel/flannel.go @@ -103,11 +103,15 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt } logrus.Debugf("The interface %s will be used by flannel", iface.Name) - ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface) - if err != nil { - return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name) + if netMode == (ipv4+ipv6) || netMode == ipv4 { + ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface) + if err != nil { + return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name) + } + logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0]) + } else { + ifaceAddr = append(ifaceAddr, nil) } - logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0]) if netMode == (ipv4 + ipv6) { ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface) @@ -116,9 +120,11 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt } logrus.Infof("Using dual-stack mode. The ipv6 address %s will be used by flannel", ifacev6Addr[0]) + } else { + ifacev6Addr = append(ifacev6Addr, nil) } if iface.MTU == 0 { - return nil, fmt.Errorf("failed to determine MTU for %s interface", ifaceAddr) + return nil, fmt.Errorf("failed to determine MTU for %s interface", iface.Name) } return &backend.ExternalInterface{