Skip to content

Commit 31c22ff

Browse files
committed
fix(bgp_policies.go): don't get BGP peers twice
Fixes a problem where a user would end up with redundant external peers in their BGP policies because getting peers is IP family agnostic and yet is run twice on the same list. This also ruined unit test consistency.
1 parent 06f5f8b commit 31c22ff

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pkg/controllers/routing/bgp_policies.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ func (nrc *NetworkRoutingController) addExternalBGPPeersDefinedSet() (map[v1core
430430
externalBgpPeers := make([]string, 0)
431431
externalBGPPeerCIDRs := make(map[v1core.IPFamily][]string)
432432

433+
if len(nrc.globalPeerRouters) > 0 {
434+
for _, peer := range nrc.globalPeerRouters {
435+
externalBgpPeers = append(externalBgpPeers, peer.Conf.NeighborAddress)
436+
}
437+
}
438+
if len(nrc.nodePeerRouters) > 0 {
439+
externalBgpPeers = append(externalBgpPeers, nrc.nodePeerRouters...)
440+
}
441+
if len(externalBgpPeers) == 0 {
442+
return externalBGPPeerCIDRs, nil
443+
}
444+
433445
for family, extPeerSetName := range map[v1core.IPFamily]string{
434446
v1core.IPv4Protocol: externalPeerSet,
435447
v1core.IPv6Protocol: externalPeerSetV6} {
@@ -438,17 +450,6 @@ func (nrc *NetworkRoutingController) addExternalBGPPeersDefinedSet() (map[v1core
438450
return externalBGPPeerCIDRs, err
439451
}
440452

441-
if len(nrc.globalPeerRouters) > 0 {
442-
for _, peer := range nrc.globalPeerRouters {
443-
externalBgpPeers = append(externalBgpPeers, peer.Conf.NeighborAddress)
444-
}
445-
}
446-
if len(nrc.nodePeerRouters) > 0 {
447-
externalBgpPeers = append(externalBgpPeers, nrc.nodePeerRouters...)
448-
}
449-
if len(externalBgpPeers) == 0 {
450-
return externalBGPPeerCIDRs, nil
451-
}
452453
for _, peer := range externalBgpPeers {
453454
ip := net.ParseIP(peer)
454455
if ip == nil {

0 commit comments

Comments
 (0)