diff --git a/client/alloc_runner_test.go b/client/alloc_runner_test.go index 3b9828493..148a33a42 100644 --- a/client/alloc_runner_test.go +++ b/client/alloc_runner_test.go @@ -31,7 +31,7 @@ func testAllocRunner(restarts bool) (*MockAllocStateUpdater, *AllocRunner) { conf.AllocDir = os.TempDir() upd := &MockAllocStateUpdater{} alloc := mock.Alloc() - consulClient, _ := NewConsulClient() + consulClient, _ := NewConsulClient(logger) if !restarts { alloc.Job.Type = structs.JobTypeBatch *alloc.Job.LookupTaskGroup(alloc.TaskGroup).RestartPolicy = structs.RestartPolicy{Attempts: 0} @@ -142,7 +142,7 @@ func TestAllocRunner_SaveRestoreState(t *testing.T) { } // Create a new alloc runner - consulClient, err := NewConsulClient() + consulClient, err := NewConsulClient(ar.logger) ar2 := NewAllocRunner(ar.logger, ar.config, upd.Update, &structs.Allocation{ID: ar.alloc.ID}, consulClient) err = ar2.RestoreState() diff --git a/client/client.go b/client/client.go index 527d43041..e33872782 100644 --- a/client/client.go +++ b/client/client.go @@ -99,7 +99,7 @@ func NewClient(cfg *config.Config) (*Client, error) { logger := log.New(cfg.LogOutput, "", log.LstdFlags) // Create the consul client - consulClient, err := NewConsulClient() + consulClient, err := NewConsulClient(logger) if err != nil { return nil, fmt.Errorf("failed to create the consul client: %v", err) } diff --git a/client/consul.go b/client/consul.go index a7f411941..85fad12bc 100644 --- a/client/consul.go +++ b/client/consul.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/consul/api" "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/nomad/structs" + "log" ) const ( @@ -13,9 +14,11 @@ const ( type ConsulClient struct { client *api.Client + + logger *log.Logger } -func NewConsulClient() (*ConsulClient, error) { +func NewConsulClient(logger *log.Logger) (*ConsulClient, error) { var err error var c *api.Client if c, err = api.NewClient(api.DefaultConfig()); err != nil { @@ -24,6 +27,7 @@ func NewConsulClient() (*ConsulClient, error) { consulClient := ConsulClient{ client: c, + logger: logger, } return &consulClient, nil diff --git a/client/task_runner_test.go b/client/task_runner_test.go index 2c3eb8928..788b0b1d5 100644 --- a/client/task_runner_test.go +++ b/client/task_runner_test.go @@ -32,7 +32,7 @@ func testTaskRunner(restarts bool) (*MockTaskStateUpdater, *TaskRunner) { upd := &MockTaskStateUpdater{} alloc := mock.Alloc() task := alloc.Job.TaskGroups[0].Tasks[0] - consulClient, _ := NewConsulClient() + consulClient, _ := NewConsulClient(logger) // Initialize the port listing. This should be done by the offer process but // we have a mock so that doesn't happen. task.Resources.Networks[0].ReservedPorts = []structs.Port{{"", 80}} @@ -164,7 +164,7 @@ func TestTaskRunner_SaveRestoreState(t *testing.T) { } // Create a new task runner - consulClient, _ := NewConsulClient() + consulClient, _ := NewConsulClient(tr.logger) tr2 := NewTaskRunner(tr.logger, tr.config, upd.Update, tr.ctx, tr.allocID, &structs.Task{Name: tr.task.Name}, tr.state, tr.restartTracker, consulClient)