@@ -61,6 +61,7 @@ type NetworkRoutingController struct {
6161 enableOverlays bool
6262 peerMultihopTtl uint8
6363 MetricsEnabled bool
64+ bgpServerStarted bool
6465}
6566
6667var (
@@ -207,6 +208,7 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
207208 }
208209 }
209210
211+ nrc .bgpServerStarted = true
210212 defer nrc .bgpServer .Shutdown ()
211213
212214 // loop forever till notified to stop on stopCh
@@ -964,6 +966,9 @@ func (nrc *NetworkRoutingController) syncNodeIPSets() error {
964966// we miss any events from API server this method which is called periodically
965967// ensure peer relationship with removed nodes is deleted. Also update Pod subnet ipset.
966968func (nrc * NetworkRoutingController ) syncInternalPeers () {
969+ nrc .mu .Lock ()
970+ defer nrc .mu .Unlock ()
971+
967972 start := time .Now ()
968973 defer func () {
969974 endTime := time .Since (start )
@@ -1015,9 +1020,7 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
10151020 }
10161021
10171022 currentNodes = append (currentNodes , nodeIP .String ())
1018- nrc .mu .Lock ()
10191023 nrc .activeNodes [nodeIP .String ()] = true
1020- nrc .mu .Unlock ()
10211024 n := & config.Neighbor {
10221025 Config : config.NeighborConfig {
10231026 NeighborAddress : nodeIP .String (),
@@ -1060,8 +1063,6 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
10601063
10611064 // find the list of the node removed, from the last known list of active nodes
10621065 removedNodes := make ([]string , 0 )
1063- nrc .mu .Lock ()
1064- defer nrc .mu .Unlock ()
10651066 for ip := range nrc .activeNodes {
10661067 stillActive := false
10671068 for _ , node := range currentNodes {
@@ -1219,35 +1220,18 @@ func rtTablesAdd(tableNumber, tableName string) error {
12191220// new node is added or old node is deleted. So peer up with new node and drop peering
12201221// from old node
12211222func (nrc * NetworkRoutingController ) OnNodeUpdate (nodeUpdate * watchers.NodeUpdate ) {
1222- nrc .mu . Lock ()
1223- defer nrc . mu . Unlock ()
1224-
1223+ if ! nrc .bgpServerStarted {
1224+ return
1225+ }
12251226 node := nodeUpdate .Node
12261227 nodeIP , _ := utils .GetNodeIP (node )
12271228 if nodeUpdate .Op == watchers .ADD {
12281229 glog .V (2 ).Infof ("Received node %s added update from watch API so peer with new node" , nodeIP )
1229- n := & config.Neighbor {
1230- Config : config.NeighborConfig {
1231- NeighborAddress : nodeIP .String (),
1232- PeerAs : nrc .defaultNodeAsnNumber ,
1233- },
1234- }
1235- if err := nrc .bgpServer .AddNeighbor (n ); err != nil {
1236- glog .Errorf ("Failed to add node %s as peer due to %s" , nodeIP , err )
1237- }
1238- nrc .activeNodes [nodeIP .String ()] = true
12391230 } else if nodeUpdate .Op == watchers .REMOVE {
12401231 glog .Infof ("Received node %s removed update from watch API, so remove node from peer" , nodeIP )
1241- n := & config.Neighbor {
1242- Config : config.NeighborConfig {
1243- NeighborAddress : nodeIP .String (),
1244- PeerAs : nrc .defaultNodeAsnNumber ,
1245- },
1246- }
1247- if err := nrc .bgpServer .DeleteNeighbor (n ); err != nil {
1248- glog .Errorf ("Failed to remove node %s as peer due to %s" , nodeIP , err )
1249- }
1250- delete (nrc .activeNodes , nodeIP .String ())
1232+ }
1233+ if nrc .bgpEnableInternal {
1234+ nrc .syncInternalPeers ()
12511235 }
12521236 nrc .disableSourceDestinationCheck ()
12531237}
@@ -1453,6 +1437,7 @@ func NewNetworkRoutingController(clientset *kubernetes.Clientset,
14531437 nrc .syncPeriod = kubeRouterConfig .RoutesSyncPeriod
14541438 nrc .clientset = clientset
14551439 nrc .activeNodes = make (map [string ]bool )
1440+ nrc .bgpServerStarted = false
14561441
14571442 nrc .ipSetHandler , err = utils .NewIPSet ()
14581443 if err != nil {
0 commit comments