Added a logger to consul client
This commit is contained in:
parent
dd875f1d2b
commit
cb34f34c12
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue