Skip to content

Commit

Permalink
network_route_controller: Avoid redundant policy sets (#98)
Browse files Browse the repository at this point in the history
* gofmt

* route_controller: Avoid redundant DefinedSet adds
  • Loading branch information
bzub committed Aug 3, 2017
1 parent f9ae00b commit f8174a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions app/controllers/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion app/watchers/network_policy_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f8174a6

Please sign in to comment.