Skip to content

Commit

Permalink
fix(bgp_policies.go): don't get BGP peers twice
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aauren committed Mar 11, 2023
1 parent 783b0aa commit ea68a39
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/controllers/routing/bgp_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ func (nrc *NetworkRoutingController) addExternalBGPPeersDefinedSet() (map[v1core
externalBgpPeers := make([]string, 0)
externalBGPPeerCIDRs := make(map[v1core.IPFamily][]string)

if len(nrc.globalPeerRouters) > 0 {
for _, peer := range nrc.globalPeerRouters {
externalBgpPeers = append(externalBgpPeers, peer.Conf.NeighborAddress)
}
}
if len(nrc.nodePeerRouters) > 0 {
externalBgpPeers = append(externalBgpPeers, nrc.nodePeerRouters...)
}
if len(externalBgpPeers) == 0 {
return externalBGPPeerCIDRs, nil
}

for family, extPeerSetName := range map[v1core.IPFamily]string{
v1core.IPv4Protocol: externalPeerSet,
v1core.IPv6Protocol: externalPeerSetV6} {
Expand All @@ -438,17 +450,6 @@ func (nrc *NetworkRoutingController) addExternalBGPPeersDefinedSet() (map[v1core
return externalBGPPeerCIDRs, err
}

if len(nrc.globalPeerRouters) > 0 {
for _, peer := range nrc.globalPeerRouters {
externalBgpPeers = append(externalBgpPeers, peer.Conf.NeighborAddress)
}
}
if len(nrc.nodePeerRouters) > 0 {
externalBgpPeers = append(externalBgpPeers, nrc.nodePeerRouters...)
}
if len(externalBgpPeers) == 0 {
return externalBGPPeerCIDRs, nil
}
for _, peer := range externalBgpPeers {
ip := net.ParseIP(peer)
if ip == nil {
Expand Down

0 comments on commit ea68a39

Please sign in to comment.