Skip to content

Commit

Permalink
Explain PortLabel handling in RegisterAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Apr 14, 2017
1 parent b55b7f9 commit 229137f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions command/agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,20 @@ func (c *ServiceClient) sync() error {
return nil
}

// RegisterAgent registers Nomad agents (client or server). Script checks are
// not supported and will return an error. Registration is asynchronous.
// RegisterAgent registers Nomad agents (client or server). The
// Service.PortLabel should be a literal port to be parsed with SplitHostPort.
// Script checks are not supported and will return an error. Registration is
// asynchronous.
//
// Agents will be deregistered when Shutdown is called.
func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error {
ops := operations{}

for _, service := range services {
id := makeAgentServiceID(role, service)

// Unlike tasks, agents don't use port labels. Agent ports are
// stored directly in the PortLabel.
host, rawport, err := net.SplitHostPort(service.PortLabel)
if err != nil {
return fmt.Errorf("error parsing port label %q from service %q: %v", service.PortLabel, service.Name, err)
Expand All @@ -340,6 +345,8 @@ func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service)
}
checkHost, checkPort := serviceReg.Address, serviceReg.Port
if check.PortLabel != "" {
// Unlike tasks, agents don't use port labels. Agent ports are
// stored directly in the PortLabel.
host, rawport, err := net.SplitHostPort(check.PortLabel)
if err != nil {
return fmt.Errorf("error parsing port label %q from check %q: %v", service.PortLabel, check.Name, err)
Expand Down

0 comments on commit 229137f

Please sign in to comment.