Skip to content

Commit 5e4ca29

Browse files
andrewsykimmurali-reddy
authored andcommitted
set iBGP export policies only if its enabled (#453)
1 parent 0809548 commit 5e4ca29

File tree

2 files changed

+165
-42
lines changed

2 files changed

+165
-42
lines changed

pkg/controllers/routing/export_policies.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
//
1515
// - by default export of all routes from the RIB to the neighbour's is denied, and explicity statements are added i
1616
// to permit the desired routes to be exported
17-
// - each node is allowed to advertise its assigned pod CIDR's to all of its iBGP peer neighbours with same ASN
17+
// - each node is allowed to advertise its assigned pod CIDR's to all of its iBGP peer neighbours with same ASN if --enable-ibgp=true
1818
// - each node is allowed to advertise its assigned pod CIDR's to all of its external BGP peer neighbours
1919
// only if --advertise-pod-cidr flag is set to true
2020
// - each node is NOT allowed to advertise its assigned pod CIDR's to all of its external BGP peer neighbours
@@ -66,40 +66,42 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
6666

6767
statements := make([]config.Statement, 0)
6868

69-
// Get the current list of the nodes from the local cache
70-
nodes := nrc.nodeLister.List()
71-
iBGPPeers := make([]string, 0)
72-
for _, node := range nodes {
73-
nodeObj := node.(*v1core.Node)
74-
nodeIP, err := utils.GetNodeIP(nodeObj)
69+
if nrc.bgpEnableInternal {
70+
// Get the current list of the nodes from the local cache
71+
nodes := nrc.nodeLister.List()
72+
iBGPPeers := make([]string, 0)
73+
for _, node := range nodes {
74+
nodeObj := node.(*v1core.Node)
75+
nodeIP, err := utils.GetNodeIP(nodeObj)
76+
if err != nil {
77+
return fmt.Errorf("Failed to find a node IP: %s", err)
78+
}
79+
iBGPPeers = append(iBGPPeers, nodeIP.String())
80+
}
81+
iBGPPeerNS, _ := table.NewNeighborSet(config.NeighborSet{
82+
NeighborSetName: "iBGPpeerset",
83+
NeighborInfoList: iBGPPeers,
84+
})
85+
err = nrc.bgpServer.ReplaceDefinedSet(iBGPPeerNS)
7586
if err != nil {
76-
return fmt.Errorf("Failed to find a node IP: %s", err)
87+
nrc.bgpServer.AddDefinedSet(iBGPPeerNS)
7788
}
78-
iBGPPeers = append(iBGPPeers, nodeIP.String())
79-
}
80-
iBGPPeerNS, _ := table.NewNeighborSet(config.NeighborSet{
81-
NeighborSetName: "iBGPpeerset",
82-
NeighborInfoList: iBGPPeers,
83-
})
84-
err = nrc.bgpServer.ReplaceDefinedSet(iBGPPeerNS)
85-
if err != nil {
86-
nrc.bgpServer.AddDefinedSet(iBGPPeerNS)
87-
}
88-
// statement to represent the export policy to permit advertising node's pod CIDR
89-
statements = append(statements,
90-
config.Statement{
91-
Conditions: config.Conditions{
92-
MatchPrefixSet: config.MatchPrefixSet{
93-
PrefixSet: "podcidrprefixset",
89+
// statement to represent the export policy to permit advertising node's pod CIDR
90+
statements = append(statements,
91+
config.Statement{
92+
Conditions: config.Conditions{
93+
MatchPrefixSet: config.MatchPrefixSet{
94+
PrefixSet: "podcidrprefixset",
95+
},
96+
MatchNeighborSet: config.MatchNeighborSet{
97+
NeighborSet: "iBGPpeerset",
98+
},
9499
},
95-
MatchNeighborSet: config.MatchNeighborSet{
96-
NeighborSet: "iBGPpeerset",
100+
Actions: config.Actions{
101+
RouteDisposition: config.ROUTE_DISPOSITION_ACCEPT_ROUTE,
97102
},
98-
},
99-
Actions: config.Actions{
100-
RouteDisposition: config.ROUTE_DISPOSITION_ACCEPT_ROUTE,
101-
},
102-
})
103+
})
104+
}
103105

104106
externalBgpPeers := make([]string, 0)
105107
if len(nrc.globalPeerRouters) != 0 {

pkg/controllers/routing/network_routes_controller_test.go

Lines changed: 132 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,12 +1151,13 @@ func Test_addExportPolicies(t *testing.T) {
11511151
{
11521152
"has nodes and services",
11531153
&NetworkRoutingController{
1154-
clientset: fake.NewSimpleClientset(),
1155-
hostnameOverride: "node-1",
1156-
bgpFullMeshMode: false,
1157-
bgpServer: gobgp.NewBgpServer(),
1158-
activeNodes: make(map[string]bool),
1159-
nodeAsnNumber: 100,
1154+
clientset: fake.NewSimpleClientset(),
1155+
hostnameOverride: "node-1",
1156+
bgpFullMeshMode: false,
1157+
bgpEnableInternal: true,
1158+
bgpServer: gobgp.NewBgpServer(),
1159+
activeNodes: make(map[string]bool),
1160+
nodeAsnNumber: 100,
11601161
},
11611162
[]*v1core.Node{
11621163
{
@@ -1251,11 +1252,12 @@ func Test_addExportPolicies(t *testing.T) {
12511252
{
12521253
"has nodes, services with external peers",
12531254
&NetworkRoutingController{
1254-
clientset: fake.NewSimpleClientset(),
1255-
hostnameOverride: "node-1",
1256-
bgpFullMeshMode: false,
1257-
bgpServer: gobgp.NewBgpServer(),
1258-
activeNodes: make(map[string]bool),
1255+
clientset: fake.NewSimpleClientset(),
1256+
hostnameOverride: "node-1",
1257+
bgpFullMeshMode: false,
1258+
bgpEnableInternal: true,
1259+
bgpServer: gobgp.NewBgpServer(),
1260+
activeNodes: make(map[string]bool),
12591261
globalPeerRouters: []*config.NeighborConfig{
12601262
{
12611263
NeighborAddress: "10.10.0.1",
@@ -1382,6 +1384,125 @@ func Test_addExportPolicies(t *testing.T) {
13821384
},
13831385
nil,
13841386
},
1387+
{
1388+
"has nodes, services with external peers and iBGP disabled",
1389+
&NetworkRoutingController{
1390+
clientset: fake.NewSimpleClientset(),
1391+
hostnameOverride: "node-1",
1392+
bgpFullMeshMode: false,
1393+
bgpEnableInternal: false,
1394+
bgpServer: gobgp.NewBgpServer(),
1395+
activeNodes: make(map[string]bool),
1396+
globalPeerRouters: []*config.NeighborConfig{
1397+
{
1398+
NeighborAddress: "10.10.0.1",
1399+
},
1400+
{
1401+
NeighborAddress: "10.10.0.2",
1402+
},
1403+
},
1404+
nodeAsnNumber: 100,
1405+
},
1406+
[]*v1core.Node{
1407+
{
1408+
ObjectMeta: metav1.ObjectMeta{
1409+
Name: "node-1",
1410+
Annotations: map[string]string{
1411+
"kube-router.io/node.asn": "100",
1412+
},
1413+
},
1414+
Status: v1core.NodeStatus{
1415+
Addresses: []v1core.NodeAddress{
1416+
{
1417+
Type: v1core.NodeInternalIP,
1418+
Address: "10.0.0.1",
1419+
},
1420+
},
1421+
},
1422+
Spec: v1core.NodeSpec{
1423+
PodCIDR: "172.20.0.0/24",
1424+
},
1425+
},
1426+
},
1427+
[]*v1core.Service{
1428+
{
1429+
ObjectMeta: metav1.ObjectMeta{
1430+
Name: "svc-1",
1431+
},
1432+
Spec: v1core.ServiceSpec{
1433+
Type: "ClusterIP",
1434+
ClusterIP: "10.0.0.1",
1435+
ExternalIPs: []string{"1.1.1.1"},
1436+
},
1437+
},
1438+
},
1439+
&config.DefinedSets{
1440+
PrefixSets: []config.PrefixSet{
1441+
{
1442+
PrefixSetName: "podcidrprefixset",
1443+
PrefixList: []config.Prefix{
1444+
{
1445+
IpPrefix: "172.20.0.0/24",
1446+
MasklengthRange: "24..24",
1447+
},
1448+
},
1449+
},
1450+
},
1451+
NeighborSets: []config.NeighborSet{},
1452+
TagSets: []config.TagSet{},
1453+
BgpDefinedSets: config.BgpDefinedSets{},
1454+
},
1455+
&config.DefinedSets{
1456+
PrefixSets: []config.PrefixSet{
1457+
{
1458+
PrefixSetName: "clusteripprefixset",
1459+
PrefixList: []config.Prefix{
1460+
{
1461+
IpPrefix: "1.1.1.1/32",
1462+
MasklengthRange: "32..32",
1463+
},
1464+
{
1465+
IpPrefix: "10.0.0.1/32",
1466+
MasklengthRange: "32..32",
1467+
},
1468+
},
1469+
},
1470+
},
1471+
NeighborSets: []config.NeighborSet{},
1472+
TagSets: []config.TagSet{},
1473+
BgpDefinedSets: config.BgpDefinedSets{},
1474+
},
1475+
&config.DefinedSets{
1476+
PrefixSets: []config.PrefixSet{},
1477+
NeighborSets: []config.NeighborSet{
1478+
{
1479+
NeighborSetName: "externalpeerset",
1480+
NeighborInfoList: []string{"10.10.0.1/32", "10.10.0.2/32"},
1481+
},
1482+
},
1483+
TagSets: []config.TagSet{},
1484+
BgpDefinedSets: config.BgpDefinedSets{},
1485+
},
1486+
[]*config.Statement{
1487+
{
1488+
Name: "kube_router_stmt0",
1489+
Conditions: config.Conditions{
1490+
MatchPrefixSet: config.MatchPrefixSet{
1491+
PrefixSet: "clusteripprefixset",
1492+
MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY,
1493+
},
1494+
MatchNeighborSet: config.MatchNeighborSet{
1495+
NeighborSet: "externalpeerset",
1496+
MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY,
1497+
},
1498+
},
1499+
Actions: config.Actions{
1500+
RouteDisposition: config.ROUTE_DISPOSITION_ACCEPT_ROUTE,
1501+
},
1502+
},
1503+
},
1504+
nil,
1505+
},
13851506
}
13861507

13871508
for _, testcase := range testcases {

0 commit comments

Comments
 (0)