From fd486fbfa432521342f869c4d3edf0192c5fb060 Mon Sep 17 00:00:00 2001 From: Wu zhengdong Date: Sun, 29 Aug 2021 00:16:06 +0800 Subject: [PATCH] Fix init node transport interface bug (#2670) 1.Fix adding node routes crash bug, which caused by uninitialized DualStackIPs param. 2.Fix ipv4 address and ipv6 address confused bug and return the first ipv4 and ipv6 ips for transport interface. Signed-off-by: Wu zhengdong --- pkg/agent/controller/noderoute/node_route_controller.go | 2 +- pkg/agent/util/net.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/agent/controller/noderoute/node_route_controller.go b/pkg/agent/controller/noderoute/node_route_controller.go index 4d8ecf1e967..8215d8ae62a 100644 --- a/pkg/agent/controller/noderoute/node_route_controller.go +++ b/pkg/agent/controller/noderoute/node_route_controller.go @@ -739,7 +739,7 @@ func getNodeMAC(node *corev1.Node) (net.HardwareAddr, error) { } func (c *Controller) getNodeTransportAddrs(node *corev1.Node) (*utilip.DualStackIPs, error) { - var transportAddrs *utilip.DualStackIPs + var transportAddrs = new(utilip.DualStackIPs) if c.networkConfig.TransportIface != "" { transportAddrsStr := node.Annotations[types.NodeTransportAddressAnnotationKey] if transportAddrsStr != "" { diff --git a/pkg/agent/util/net.go b/pkg/agent/util/net.go index abaee70f683..dec5cf412c1 100644 --- a/pkg/agent/util/net.go +++ b/pkg/agent/util/net.go @@ -165,9 +165,11 @@ func GetIPNetDeviceByName(ifaceName string) (v4IPNet *net.IPNet, v6IPNet *net.IP if ipNet, ok := addr.(*net.IPNet); ok { if ipNet.IP.IsGlobalUnicast() { if ipNet.IP.To4() != nil { + if v4IPNet == nil { + v4IPNet = ipNet + } + } else if v6IPNet == nil { v6IPNet = ipNet - } else { - v4IPNet = ipNet } } }