Skip to content

Commit

Permalink
proxy/mucp: add support for multi-tenancy (micro#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-toogood authored Jun 26, 2020
1 parent a8fc559 commit ee02511
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions proxy/mucp/mucp.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route

// only process routes with this network
if net, ok := md.Get("Micro-Network"); ok && len(net) > 0 {
if route.Network != net {
if route.Network != router.DefaultNetwork && route.Network != net {
// skip routes that don't mwatch
continue
}
Expand Down Expand Up @@ -183,14 +183,12 @@ func (p *Proxy) getLink(r router.Route) (client.Client, error) {

func (p *Proxy) getRoute(ctx context.Context, service string) ([]router.Route, error) {
// lookup the route cache first
p.Lock()
p.RLock()
cached, ok := p.Routes[service]
p.RUnlock()
if ok {
p.Unlock()
routes := toSlice(cached)
return p.filterRoutes(ctx, routes), nil
return p.filterRoutes(ctx, toSlice(cached)), nil
}
p.Unlock()

// cache routes for the service
routes, err := p.cacheRoutes(service)
Expand All @@ -203,7 +201,7 @@ func (p *Proxy) getRoute(ctx context.Context, service string) ([]router.Route, e

func (p *Proxy) cacheRoutes(service string) ([]router.Route, error) {
// lookup the routes in the router
results, err := p.Router.Lookup(router.QueryService(service))
results, err := p.Router.Lookup(router.QueryService(service), router.QueryNetwork("*"))
if err != nil {
// assumption that we're ok with stale routes
logger.Debugf("Failed to lookup route for %s: %v", service, err)
Expand Down Expand Up @@ -290,13 +288,15 @@ func (p *Proxy) watchRoutes() {
// route watcher
w, err := p.Router.Watch()
if err != nil {
logger.Debugf("Error watching router: %v", err)
return
}
defer w.Stop()

for {
event, err := w.Next()
if err != nil {
logger.Debugf("Error watching router: %v", err)
return
}

Expand Down

0 comments on commit ee02511

Please sign in to comment.