Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
truenas-rk3588
kube-router
Commits
d0501c07
Commit
d0501c07
authored
3 years ago
by
Aaron U'Ren
Browse files
Options
Download
Email Patches
Plain Diff
fix(injectRoute): cleanup tunnels & routes when peer drops
parent
94640acf
base
dependabot/go_modules/github.com/aws/aws-sdk-go-1.44.211
dependabot/go_modules/github.com/osrg/gobgp/v3-3.11.0
dependabot/go_modules/k8s.io/api-0.26.2
dependabot/go_modules/k8s.io/apimachinery-0.26.2
dependabot/go_modules/k8s.io/cri-api-0.26.2
master
rel-v0.0.1
release-test/22.02.3
release/21.08-BETA.1
release/21.08-BETA.2
release/22.02
release/22.02-RC.1
release/22.02-RC.2
release/22.02-test
release/22.02.1
release/22.02.2
release/22.02.3
release/22.02.4
release/22.12
release/22.12-BETA.1
release/22.12-BETA.2
release/22.12-RC.1
release/22.12.1
release/22.12.2
release/22.12.3
release/22.12.4
release/22.2-RC.1
release/23.10-BETA.1
release/23.10-RC.1
release/23.10.0
release/23.10.1
release/23.10.1.2
release/23.10.1.3
release/23.10.2
release/24.04-BETA.1
release/24.04-RC.1
release/24.04.0
stable/angelfish
stable/angelfish-backup-06-04-22
stable/angelfish-backup-28-05-22
stable/bluefin
stable/cobia
stable/dragonfish
testing-refine-branchout-process
testing-refine-branchout-process2
tmprelease/test-21.08
tmprelease/test-21.09
tmprelease/test2-21.09
tmprelease/test3-21.09
tmprelease/test4-21.09
truenas/master
truenas/master-backup-03-4-22
truenas/master-backup-2-7-23
truenas/master-backup-21-08-22
truenas/master-backup-29-05-22
TS-24.04-RC.1
TS-24.04-BETA.1
TS-23.10.2
TS-23.10.1.3
TS-23.10.1.2
TS-23.10.1.1
TS-23.10.1
TS-23.10.0.1
TS-23.10.0
TS-23.10-RC.1
TS-23.10-BETA.1
TS-22.12.4.2
TS-22.12.4.1
TS-22.12.4
TS-22.12.3.3
TS-22.12.3.2
TS-22.12.3.1
TS-22.12.3
TS-22.12.2
TS-22.12.1
TS-22.12.0
TS-22.12-RC.1
TS-22.12-BETA.2
TS-22.12-BETA.1
TS-22.12-ALPHA.1
TS-22.02.4
TS-22.02.3
TS-22.02.2.1
TS-22.02.2
TS-22.02.1
TS-22.02.0.1
TS-22.02.0
TS-22.2.0
TS-22.02.RELEASE.1
TS-22.02-RC.2
TS-22.02-RC.1
TS-22.02-RC.1-2
TS-22.02-RC.1-1
TS-21.08-BETA.2
TS-21.08-BETA.1
TS-12.12.3
DN110M-CS-v2.0
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/controllers/routing/network_routes_controller.go
+34
-1
pkg/controllers/routing/network_routes_controller.go
with
34 additions
and
1 deletion
+34
-1
pkg/controllers/routing/network_routes_controller.go
View file @
d0501c07
...
...
@@ -572,7 +572,21 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error {
// on the host (rather than creating a new one or updating an existing one), and then return.
if
path
.
IsWithdraw
{
klog
.
V
(
2
)
.
Infof
(
"Removing route: '%s via %s' from peer in the routing table"
,
dst
,
nextHop
)
return
netlink
.
RouteDel
(
route
)
// The path might be withdrawn because the peer became unestablished or it may be withdrawn because just the
// path was withdrawn. Check to see if the peer is still established before deciding whether to clean the
// tunnel and tunnel routes or whether to just delete the destination route.
peerEstablished
,
err
:=
nrc
.
isPeerEstablished
(
nextHop
.
String
())
if
err
!=
nil
{
klog
.
Errorf
(
"encountered error while checking peer status: %v"
,
err
)
}
if
err
==
nil
&&
!
peerEstablished
{
klog
.
V
(
1
)
.
Infof
(
"Peer '%s' was not found any longer, removing tunnel and routes"
,
nextHop
.
String
())
nrc
.
cleanupTunnel
(
dst
,
tunnelName
)
return
nil
}
else
{
return
netlink
.
RouteDel
(
route
)
}
}
// Alright, everything is in place, and we have our route configured, let's add it to the host's routing table
...
...
@@ -580,6 +594,25 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error {
return
netlink
.
RouteReplace
(
route
)
}
func
(
nrc
*
NetworkRoutingController
)
isPeerEstablished
(
peerIP
string
)
(
bool
,
error
)
{
var
peerDisconnected
bool
peerFunc
:=
func
(
peer
*
gobgpapi
.
Peer
)
{
if
peer
.
Conf
.
NeighborAddress
==
peerIP
{
if
peer
.
State
.
SessionState
!=
gobgpapi
.
PeerState_ESTABLISHED
{
peerDisconnected
=
true
}
}
}
err
:=
nrc
.
bgpServer
.
ListPeer
(
context
.
Background
(),
&
gobgpapi
.
ListPeerRequest
{
Address
:
peerIP
,
},
peerFunc
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"unable to list peers to see if tunnel & routes need to be removed: %v"
,
err
)
}
return
peerDisconnected
,
nil
}
// cleanupTunnels removes any traces of tunnels / routes that were setup by nrc.setupOverlayTunnel() and are no longer
// needed. All errors are logged only, as we want to attempt to perform all cleanup actions regardless of their success
func
(
nrc
*
NetworkRoutingController
)
cleanupTunnel
(
destinationSubnet
*
net
.
IPNet
,
tunnelName
string
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help