Skip to content

Commit

Permalink
Always create a consul.Syncer. Use a default Consul Config if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean- committed Jun 10, 2016
1 parent aff951c commit 91582dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion client/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func NewExecutor(logger *log.Logger) Executor {
shutdownCh := make(chan struct{})
cs, err := consul.NewSyncer(nil, shutdownCh, logger)
if err != nil {
return err
logger.Printf("[ERROR] executor: failed to allocate new Consul Syncer: %v", err)
return nil
}

exec := &UniversalExecutor{
Expand Down
35 changes: 18 additions & 17 deletions command/agent/consul/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/go-multierror"

cconfig "github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/nomad/types"
Expand Down Expand Up @@ -108,46 +109,46 @@ type Syncer struct {
}

// NewSyncer returns a new consul.Syncer
func NewSyncer(config *config.ConsulConfig, shutdownCh chan struct{}, logger *log.Logger) (*Syncer, error) {
func NewSyncer(consulConfig *config.ConsulConfig, shutdownCh chan struct{}, logger *log.Logger) (*Syncer, error) {
var err error
var c *consul.Client

cfg := consul.DefaultConfig()

// If a nil config was provided, fall back to the default config
if config == nil {
config = cfg
if consulConfig == nil {
consulConfig = cconfig.DefaultConfig().ConsulConfig
}

if config.Addr != "" {
cfg.Address = config.Addr
if consulConfig.Addr != "" {
cfg.Address = consulConfig.Addr
}
if config.Token != "" {
cfg.Token = config.Token
if consulConfig.Token != "" {
cfg.Token = consulConfig.Token
}
if config.Auth != "" {
if consulConfig.Auth != "" {
var username, password string
if strings.Contains(config.Auth, ":") {
split := strings.SplitN(config.Auth, ":", 2)
if strings.Contains(consulConfig.Auth, ":") {
split := strings.SplitN(consulConfig.Auth, ":", 2)
username = split[0]
password = split[1]
} else {
username = config.Auth
username = consulConfig.Auth
}

cfg.HttpAuth = &consul.HttpBasicAuth{
Username: username,
Password: password,
}
}
if config.EnableSSL {
if consulConfig.EnableSSL {
cfg.Scheme = "https"
tlsCfg := consul.TLSConfig{
Address: cfg.Address,
CAFile: config.CAFile,
CertFile: config.CertFile,
KeyFile: config.KeyFile,
InsecureSkipVerify: !config.VerifySSL,
CAFile: consulConfig.CAFile,
CertFile: consulConfig.CertFile,
KeyFile: consulConfig.KeyFile,
InsecureSkipVerify: !consulConfig.VerifySSL,
}
tlsClientCfg, err := consul.SetupTLSConfig(&tlsCfg)
if err != nil {
Expand All @@ -157,7 +158,7 @@ func NewSyncer(config *config.ConsulConfig, shutdownCh chan struct{}, logger *lo
TLSClientConfig: tlsClientCfg,
}
}
if config.EnableSSL && !config.VerifySSL {
if consulConfig.EnableSSL && !consulConfig.VerifySSL {
cfg.HttpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
Expand Down
8 changes: 7 additions & 1 deletion nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,12 @@ func TestTaskDiff(t *testing.T) {
Old: "foo",
New: "bar",
},
{
Type: DiffTypeNone,
Name: "ServiceID",
Old: "",
New: "",
},
},
},
},
Expand Down Expand Up @@ -2821,7 +2827,7 @@ func TestTaskDiff(t *testing.T) {
}

if !reflect.DeepEqual(actual, c.Expected) {
t.Fatalf("case %d: got:\n%#v\n want:\n%#v\n",
t.Errorf("case %d: got:\n%#v\n want:\n%#v\n",
i+1, actual, c.Expected)
}
}
Expand Down

0 comments on commit 91582dc

Please sign in to comment.