mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-10 09:21:04 +02:00
Fix to avoid re-adding existing BGP export policy, and policy assignment (#200)
Fixes #197
This commit is contained in:
parent
50173e3b73
commit
665e6676b2
@ -492,12 +492,12 @@ func (nrc *NetworkRoutingController) AdvertiseClusterIp(clusterIp string) error
|
|||||||
|
|
||||||
// Each node advertises its pod CIDR to the nodes with same ASN (iBGP peers) and to the global BGP peer
|
// Each node advertises its pod CIDR to the nodes with same ASN (iBGP peers) and to the global BGP peer
|
||||||
// or per node BGP peer. Each node ends up advertising not only pod CIDR assigned to the self but other
|
// or per node BGP peer. Each node ends up advertising not only pod CIDR assigned to the self but other
|
||||||
// routers learned to the node pod CIDR's as well to global BGP peer or per node BGP peers. external BGP
|
// learned routes to the node pod CIDR's as well to global BGP peer or per node BGP peers. external BGP
|
||||||
// peer will randomly (since all path have equal selection attributes) select the routes from multiple
|
// peer will randomly (since all path have equal selection attributes) select the routes from multiple
|
||||||
// routes to a pod CIDR which will result in extra hop. To prevent this behaviour this methods add
|
// routes to a pod CIDR which will result in extra hop. To prevent this behaviour this methods add
|
||||||
// defult export policy to reject. and explicit policy is added so that each node only advertised the
|
// defult export policy to reject everything and an explicit policy is added so that each node only
|
||||||
// pod CIDR assigned to it. Additionally export policy is added so that a node advertises cluster IP's
|
// advertised the pod CIDR assigned to it. Additionally export policy is added so that each node
|
||||||
// only to the external BGP peers.
|
// advertises cluster IP's ONLY to the external BGP peers (and not to iBGP peers).
|
||||||
func (nrc *NetworkRoutingController) addExportPolicies() error {
|
func (nrc *NetworkRoutingController) addExportPolicies() error {
|
||||||
|
|
||||||
cidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
|
cidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
|
||||||
@ -596,14 +596,32 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
|
|||||||
return errors.New("Failed to create new policy: " + err.Error())
|
return errors.New("Failed to create new policy: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = nrc.bgpServer.ReplacePolicy(policy, false, false)
|
policyAlreadyExists := false
|
||||||
if err != nil {
|
policyList := nrc.bgpServer.GetPolicy()
|
||||||
|
for _, existingPolicy := range policyList {
|
||||||
|
if existingPolicy.Name == "kube_router" {
|
||||||
|
policyAlreadyExists = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !policyAlreadyExists {
|
||||||
err = nrc.bgpServer.AddPolicy(policy, false)
|
err = nrc.bgpServer.AddPolicy(policy, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Failed to add policy: " + err.Error())
|
return errors.New("Failed to add policy: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
policyAssignmentExists := false
|
||||||
|
_, existingPolicyAssignments, err := nrc.bgpServer.GetPolicyAssignment("", table.POLICY_DIRECTION_EXPORT)
|
||||||
|
if err == nil {
|
||||||
|
for _, existingPolicyAssignment := range existingPolicyAssignments {
|
||||||
|
if existingPolicyAssignment.Name == "kube_router" {
|
||||||
|
policyAssignmentExists = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !policyAssignmentExists {
|
||||||
err = nrc.bgpServer.AddPolicyAssignment("",
|
err = nrc.bgpServer.AddPolicyAssignment("",
|
||||||
table.POLICY_DIRECTION_EXPORT,
|
table.POLICY_DIRECTION_EXPORT,
|
||||||
[]*config.PolicyDefinition{&definition},
|
[]*config.PolicyDefinition{&definition},
|
||||||
@ -611,6 +629,7 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Failed to add policy assignment: " + err.Error())
|
return errors.New("Failed to add policy assignment: " + err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// configure default BGP export policy to reject
|
// configure default BGP export policy to reject
|
||||||
pd := make([]*config.PolicyDefinition, 0)
|
pd := make([]*config.PolicyDefinition, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user