diff --git a/api/agent.go b/api/agent.go index 338245502..e8b063ff1 100644 --- a/api/agent.go +++ b/api/agent.go @@ -60,10 +60,14 @@ func (a *Agent) populateCache(self *AgentSelf) { a.nodeName = self.Member.Name } if a.datacenter == "" { - a.datacenter, _ = self.Member.Tags["dc"] + if val, ok := self.Config["Datacenter"]; ok { + a.datacenter, _ = val.(string) + } } if a.region == "" { - a.region, _ = self.Member.Tags["region"] + if val, ok := self.Config["Region"]; ok { + a.region, _ = val.(string) + } } } diff --git a/api/fs.go b/api/fs.go index c52a9329b..ec8551664 100644 --- a/api/fs.go +++ b/api/fs.go @@ -57,8 +57,25 @@ func (a *AllocFS) getNodeClient(node *Node, allocID string, q **QueryOptions) (* return nil, fmt.Errorf("http addr of the node where alloc %q is running is not advertised", allocID) } + region := "" + if q != nil && *q != nil && (*q).Region != "" { + region = (*q).Region + } else if a.client.config.Region != "" { + // Use the region from the client + region = a.client.config.Region + } else { + // Use the region from the agent + agentRegion, err := a.client.Agent().Region() + if err != nil { + return nil, err + } + region = agentRegion + } + // Get an API client for the node - nodeClient, err := NewClient(a.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled)) + conf := a.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled) + conf.TLSConfig.TLSServerName = fmt.Sprintf("client.%s.nomad", region) + nodeClient, err := NewClient(conf) if err != nil { return nil, err }