Skip to content

Commit

Permalink
Fix init node transport interface bug (#2670) (#2677)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Co-authored-by: Wu zhengdong <[email protected]>
  • Loading branch information
antoninbas and Wu zhengdong authored Aug 31, 2021
1 parent 7b49d9a commit 93d2d64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/controller/noderoute/node_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
6 changes: 4 additions & 2 deletions pkg/agent/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 93d2d64

Please sign in to comment.