Fix to avoid re-adding existing BGP export policy, and policy assignment (#200)

Fixes #197
This commit is contained in:
Murali Reddy 2017-10-16 00:50:41 +05:30 committed by GitHub
parent 50173e3b73
commit 665e6676b2

View File

@ -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
// 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
// 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
// pod CIDR assigned to it. Additionally export policy is added so that a node advertises cluster IP's
// only to the external BGP peers.
// defult export policy to reject everything and an explicit policy is added so that each node only
// advertised the pod CIDR assigned to it. Additionally export policy is added so that each node
// advertises cluster IP's ONLY to the external BGP peers (and not to iBGP peers).
func (nrc *NetworkRoutingController) addExportPolicies() error {
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())
}
err = nrc.bgpServer.ReplacePolicy(policy, false, false)
if err != nil {
policyAlreadyExists := false
policyList := nrc.bgpServer.GetPolicy()
for _, existingPolicy := range policyList {
if existingPolicy.Name == "kube_router" {
policyAlreadyExists = true
}
}
if !policyAlreadyExists {
err = nrc.bgpServer.AddPolicy(policy, false)
if err != nil {
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("",
table.POLICY_DIRECTION_EXPORT,
[]*config.PolicyDefinition{&definition},
@ -611,6 +629,7 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
if err != nil {
return errors.New("Failed to add policy assignment: " + err.Error())
}
}
// configure default BGP export policy to reject
pd := make([]*config.PolicyDefinition, 0)