Skip to content

Commit

Permalink
Merge pull request #953 from aauren/bgp_graceful_restart_time
Browse files Browse the repository at this point in the history
Allow Setting BGP Restart Time
  • Loading branch information
aauren authored Jul 10, 2020
2 parents 27857d3 + b07f53f commit 3fd8dc5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage of kube-router:
--advertise-pod-cidr Add Node's POD cidr to the RIB so that it gets advertised to the BGP peers. (default true)
--bgp-graceful-restart Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts
--bgp-graceful-restart-deferral-time duration BGP Graceful restart deferral time according to RFC4724 4.1, maximum 18h. (default 6m0s)
--bgp-graceful-restart-time duration BGP Graceful restart time according to RFC4724 3, maximum 4095s. (default 1m30s)
--bgp-port uint16 The port open for incoming BGP connections and to use for connecting with other BGP peers. (default 179)
--cache-sync-timeout duration The timeout for cache synchronization (e.g. '5s', '1m'). Must be greater than 0. (default 1m0s)
--cleanup-config Cleanup iptables rules, ipvs, ipset configuration and exit.
Expand Down
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
5 changes: 4 additions & 1 deletion pkg/controllers/routing/bgp_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
n.GracefulRestart = config.GracefulRestart{
Config: config.GracefulRestartConfig{
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 3fd8dc5

Please sign in to comment.