Skip to content

Commit

Permalink
Added common bgp config error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Aug 12, 2023
1 parent 98e3e52 commit 5e62ffd
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,18 @@ func (m *Manager) SelectLoxiLBRoles(sendSigCh bool, loxiLBSelMasterEvent chan bo
}
}

func (m *Manager) checkHandleBGPCfgErrors(loxiAliveCh chan *api.LoxiClient, peer *api.LoxiClient, err error) {
if strings.Contains(err.Error(), "connection refused") ||
strings.Contains(err.Error(), "deadline") {
time.Sleep(2 * time.Second)
if !peer.DoBGPCfg {
klog.Infof(" client (%s) requeued ", peer.Host)
peer.DoBGPCfg = true
loxiAliveCh <- peer
}
}
}

func (m *Manager) manageLoxiLbLifeCycle(stopCh <-chan struct{}, loxiAliveCh chan *api.LoxiClient, loxiPurgeCh chan *api.LoxiClient, masterEventCh <-chan bool) {
loop:
for {
Expand Down Expand Up @@ -1298,14 +1310,7 @@ loop:
klog.Infof("set-bgp-global success")
} else {
klog.Infof("set-bgp-global failed(%s)", err)
if strings.Contains(err.Error(), "connection refused") {
time.Sleep(2 * time.Second)
if !aliveClient.DoBGPCfg {
klog.Infof(" client (%s) requeued ", aliveClient.Host)
aliveClient.DoBGPCfg = true
loxiAliveCh <- aliveClient
}
}
m.checkHandleBGPCfgErrors(loxiAliveCh, aliveClient, err)
}

for _, bgpPeer := range bgpPeers {
Expand All @@ -1314,29 +1319,15 @@ loop:
klog.Infof("set-bgp-neigh(%s->%s) success", aliveClient.Host, bgpPeer.Host)
} else {
klog.Infof("set-bgp-neigh(%s->%s) failed(%s)", aliveClient.Host, bgpPeer.Host, err)
if strings.Contains(err.Error(), "connection refused") {
time.Sleep(2 * time.Second)
if !aliveClient.DoBGPCfg {
klog.Infof(" client (%s) requeued ", aliveClient.Host)
aliveClient.DoBGPCfg = true
loxiAliveCh <- aliveClient
}
}
m.checkHandleBGPCfgErrors(loxiAliveCh, aliveClient, err)
}

bgpNeighCfg1, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), aliveClient.Host, m.networkConfig.ListenBGPPort)
if err := bgpPeer.BGP().CreateNeigh(ctx, &bgpNeighCfg1); err == nil {
klog.Infof("set-bgp-neigh(%s->%s) success", bgpPeer.Host, aliveClient.Host)
} else {
klog.Infof("set-bgp-neigh(%s->%s) failed(%s)", bgpPeer.Host, aliveClient.Host, err)
if strings.Contains(err.Error(), "connection refused") {
time.Sleep(2 * time.Second)
if !bgpPeer.DoBGPCfg {
klog.Infof(" client (%s) requeued ", bgpPeer.Host)
bgpPeer.DoBGPCfg = true
loxiAliveCh <- bgpPeer
}
}
m.checkHandleBGPCfgErrors(loxiAliveCh, bgpPeer, err)
}
}

Expand All @@ -1362,14 +1353,7 @@ loop:
klog.Infof("set-ebgp-neigh(%s:%v) cfg success", bgpRemoteIP.String(), asid)
} else {
klog.Infof("set-ebgp-neigh(%s:%v) cfg - failed (%s)", bgpRemoteIP.String(), asid, err)
if strings.Contains(err.Error(), "connection refused") {
klog.Infof("set-ebgp-neigh(%s:%v) cfg - failed", bgpRemoteIP.String(), asid)
time.Sleep(2 * time.Second)
if !aliveClient.DoBGPCfg {
loxiAliveCh <- aliveClient
aliveClient.DoBGPCfg = true
}
}
m.checkHandleBGPCfgErrors(loxiAliveCh, aliveClient, err)
}
}
}
Expand Down

0 comments on commit 5e62ffd

Please sign in to comment.