network_route_controller: Avoid redundant policy sets (#98)

* gofmt

* route_controller: Avoid redundant DefinedSet adds
This commit is contained in:
Bryan Zubrod 2017-08-03 02:49:20 -05:00 committed by GitHub
parent f9ae00be10
commit f8174a66be
2 changed files with 14 additions and 5 deletions

View File

@ -256,12 +256,15 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
podCidrPrefixSet, err := table.NewPrefixSet(config.PrefixSet{
PrefixSetName: "podcidrprefixset",
PrefixList: []config.Prefix{
config.Prefix{
{
IpPrefix: cidr,
},
},
})
nrc.bgpServer.AddDefinedSet(podCidrPrefixSet)
err = nrc.bgpServer.ReplaceDefinedSet(podCidrPrefixSet)
if err != nil {
nrc.bgpServer.AddDefinedSet(podCidrPrefixSet)
}
// creates prefix set to represent all the cluster IP associated with the services
clusterIpPrefixList := make([]config.Prefix, 0)
@ -273,7 +276,10 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
PrefixSetName: "clusteripprefixset",
PrefixList: clusterIpPrefixList,
})
nrc.bgpServer.AddDefinedSet(clusterIpPrefixSet)
err = nrc.bgpServer.ReplaceDefinedSet(clusterIpPrefixSet)
if err != nil {
nrc.bgpServer.AddDefinedSet(clusterIpPrefixSet)
}
statements := make([]config.Statement, 0)
@ -302,7 +308,10 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
NeighborSetName: "externalpeerset",
NeighborInfoList: externalBgpPeers,
})
nrc.bgpServer.AddDefinedSet(ns)
err = nrc.bgpServer.ReplaceDefinedSet(ns)
if err != nil {
nrc.bgpServer.AddDefinedSet(ns)
}
// statement to represent the export policy to permit advertising cluster IP's
// only to the global BGP peer or node specific BGP peer
statements = append(statements, config.Statement{

View File

@ -89,7 +89,7 @@ func StartNetworkPolicyWatcher(clientset *kubernetes.Clientset, resyncPeriod tim
if v1NetworkPolicy {
lw = cache.NewListWatchFromClient(clientset.Networking().RESTClient(), "networkpolicies", metav1.NamespaceAll, fields.Everything())
npw.networkPolicyLister, npw.networkPolicyController = cache.NewIndexerInformer(
lw, &networking.NetworkPolicy{}, resyncPeriod, eventHandler,
lw, &networking.NetworkPolicy{}, resyncPeriod, eventHandler,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
} else {