Skip to content

Commit

Permalink
add go-discover support to client
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed May 10, 2018
1 parent 3212e38 commit 92af6a5
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/boltdb/bolt"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
discover "github.com/hashicorp/go-discover"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config"
Expand Down Expand Up @@ -619,6 +620,18 @@ func (c *Client) SetServers(in []string) error {
return c.setServersImpl(in, false)
}

func (c *Client) getServerAddr(srv string) (string, error) {
if strings.HasPrefix(srv, "provider=") {
disc := &discover.Discover{}
discoveredServer, err := disc.Addrs(srv, c.logger)
if err != nil || len(discoveredServer) != 1 {
return "", err
}
return discoveredServer[0], nil
}
return srv, nil
}

// setServersImpl sets a new list of nomad servers to connect to. If force is
// set, we add the server to the internal serverlist even if the server could not
// be pinged. An error is returned if no endpoints were valid when non-forcing.
Expand All @@ -636,7 +649,14 @@ func (c *Client) setServersImpl(in []string, force bool) error {
for _, s := range in {
go func(srv string) {
defer wg.Done()
addr, err := resolveServer(srv)

server, err := c.getServerAddr(srv)
if err != nil {
c.logger.Printf("[DEBUG] client: ignoring server %s due to resolution error: %v", srv, err)
merr.Errors = append(merr.Errors, err)
return
}
addr, err := resolveServer(server)
if err != nil {
c.logger.Printf("[DEBUG] client: ignoring server %s due to resolution error: %v", srv, err)
merr.Errors = append(merr.Errors, err)
Expand Down

0 comments on commit 92af6a5

Please sign in to comment.