Skip to content

Commit

Permalink
Allow setting BGP Graceful restart time from CLI
Browse files Browse the repository at this point in the history
Default value remains the same as GoBGP (90s)
  • Loading branch information
jraby authored and aauren committed Jul 10, 2020
1 parent 27857d3 commit 1c594b2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/cmd/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func (kr *KubeRouter) Run() error {
}

if kr.Config.BGPGracefulRestart {
if kr.Config.BGPGracefulRestartTime > time.Second*4095 {
return errors.New("BGPGracefuleRestartTime should be less than 4095 seconds")
}
if kr.Config.BGPGracefulRestartTime <= 0 {
return errors.New("BGPGracefuleRestartTime must be positive")
}

if kr.Config.BGPGracefulRestartDeferralTime > time.Hour*18 {
return errors.New("BGPGracefuleRestartDeferralTime should be less than 18 hours")
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/controllers/routing/bgp_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
if nrc.bgpGracefulRestart {
n.GracefulRestart = config.GracefulRestart{
Config: config.GracefulRestartConfig{
Enabled: true,
Enabled: true,
RestartTime: uint16(nrc.bgpGracefulRestartTime.Seconds()),
DeferralTime: uint16(nrc.bgpGracefulRestartDeferralTime.Seconds()),
},
State: config.GracefulRestartState{
Expand Down Expand Up @@ -196,13 +197,15 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
}

// connectToExternalBGPPeers adds all the configured eBGP peers (global or node specific) as neighbours
func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*config.Neighbor, bgpGracefulRestart bool, bgpGracefulRestartDeferralTime time.Duration, peerMultihopTtl uint8) error {
func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*config.Neighbor, bgpGracefulRestart bool, bgpGracefulRestartDeferralTime time.Duration,
bgpGracefulRestartTime time.Duration, peerMultihopTtl uint8) error {
for _, n := range peerNeighbors {

if bgpGracefulRestart {
n.GracefulRestart = config.GracefulRestart{
Config: config.GracefulRestartConfig{
Enabled: true,
RestartTime: uint16(bgpGracefulRestartTime.Seconds()),
DeferralTime: uint16(bgpGracefulRestartDeferralTime.Seconds()),
},
State: config.GracefulRestartState{
Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type NetworkRoutingController struct {
bgpFullMeshMode bool
bgpEnableInternal bool
bgpGracefulRestart bool
bgpGracefulRestartTime time.Duration
bgpGracefulRestartDeferralTime time.Duration
ipSetHandler *utils.IPSet
enableOverlays bool
Expand Down Expand Up @@ -832,7 +833,8 @@ func (nrc *NetworkRoutingController) startBgpServer() error {
}

if len(nrc.globalPeerRouters) != 0 {
err := connectToExternalBGPPeers(nrc.bgpServer, nrc.globalPeerRouters, nrc.bgpGracefulRestart, nrc.bgpGracefulRestartDeferralTime, nrc.peerMultihopTTL)
err := connectToExternalBGPPeers(nrc.bgpServer, nrc.globalPeerRouters, nrc.bgpGracefulRestart,
nrc.bgpGracefulRestartDeferralTime, nrc.bgpGracefulRestartTime, nrc.peerMultihopTTL)
if err != nil {
err2 := nrc.bgpServer.Stop()
if err2 != nil {
Expand Down Expand Up @@ -874,6 +876,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
nrc.bgpEnableInternal = kubeRouterConfig.EnableiBGP
nrc.bgpGracefulRestart = kubeRouterConfig.BGPGracefulRestart
nrc.bgpGracefulRestartDeferralTime = kubeRouterConfig.BGPGracefulRestartDeferralTime
nrc.bgpGracefulRestartTime = kubeRouterConfig.BGPGracefulRestartTime
nrc.peerMultihopTTL = kubeRouterConfig.PeerMultihopTtl
nrc.enablePodEgress = kubeRouterConfig.EnablePodEgress
nrc.syncPeriod = kubeRouterConfig.RoutesSyncPeriod
Expand Down
4 changes: 4 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type KubeRouterConfig struct {
AdvertiseNodePodCidr bool
AdvertiseLoadBalancerIp bool
BGPGracefulRestart bool
BGPGracefulRestartTime time.Duration
BGPGracefulRestartDeferralTime time.Duration
BGPPort uint16
CacheSyncTimeout time.Duration
Expand Down Expand Up @@ -73,6 +74,7 @@ func NewKubeRouterConfig() *KubeRouterConfig {
IPTablesSyncPeriod: 5 * time.Minute,
IpvsGracefulPeriod: 30 * time.Second,
RoutesSyncPeriod: 5 * time.Minute,
BGPGracefulRestartTime: 90 * time.Second,
BGPGracefulRestartDeferralTime: 360 * time.Second,
EnableOverlay: true,
OverlayType: "subnet",
Expand Down Expand Up @@ -146,6 +148,8 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
"Each node in the cluster will setup BGP peering with rest of the nodes.")
fs.BoolVar(&s.BGPGracefulRestart, "bgp-graceful-restart", false,
"Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts")
fs.DurationVar(&s.BGPGracefulRestartTime, "bgp-graceful-restart-time", s.BGPGracefulRestartTime,
"BGP Graceful restart time according to RFC4724 3, maximum 4095s.")
fs.DurationVar(&s.BGPGracefulRestartDeferralTime, "bgp-graceful-restart-deferral-time", s.BGPGracefulRestartDeferralTime,
"BGP Graceful restart deferral time according to RFC4724 4.1, maximum 18h.")
fs.Uint16Var(&s.BGPPort, "bgp-port", DEFAULT_BGP_PORT,
Expand Down

0 comments on commit 1c594b2

Please sign in to comment.