From 73da65d566059e0644733a3cf26a4d44c5390af3 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 27 Mar 2017 17:38:16 -0700 Subject: [PATCH 1/2] Fix TLS use in AllocFS API and region/dc detection --- api/agent.go | 4 ++-- api/fs.go | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/agent.go b/api/agent.go index 33824550267..5ec2b4c43fe 100644 --- a/api/agent.go +++ b/api/agent.go @@ -60,10 +60,10 @@ func (a *Agent) populateCache(self *AgentSelf) { a.nodeName = self.Member.Name } if a.datacenter == "" { - a.datacenter, _ = self.Member.Tags["dc"] + a.datacenter, _ = self.Config["Datacenter"].(string) } if a.region == "" { - a.region, _ = self.Member.Tags["region"] + a.region, _ = self.Config["Region"].(string) } } diff --git a/api/fs.go b/api/fs.go index c52a9329be1..ec8551664fe 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 } From 26e60737609e8087d7f4f4a34611bf38fd0bb22a Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 27 Mar 2017 20:54:43 -0700 Subject: [PATCH 2/2] Remove overly clever code --- api/agent.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/agent.go b/api/agent.go index 5ec2b4c43fe..e8b063ff181 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.Config["Datacenter"].(string) + if val, ok := self.Config["Datacenter"]; ok { + a.datacenter, _ = val.(string) + } } if a.region == "" { - a.region, _ = self.Config["Region"].(string) + if val, ok := self.Config["Region"]; ok { + a.region, _ = val.(string) + } } }