Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllocRunner v2 Feature Branch PR #4792

Merged
merged 152 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
deede95
Initial V2 alloc runner
dadgar Jun 22, 2018
15c0731
artifact task hook
schmichael Jun 27, 2018
0892aca
begin adding AllocRunner.Update
schmichael Jun 28, 2018
53a4b3f
example redis job "runs" on arv2! see below
schmichael Jun 29, 2018
2d90ec6
Copy TR.Config vals to TR
schmichael Jun 29, 2018
124ad51
tr: start update/shutdown logic
schmichael Jun 29, 2018
256bc5a
tr: don't lock for immutable fields
schmichael Jun 29, 2018
1e24cd6
tr: skip error/success saving
schmichael Jun 29, 2018
07d5bac
tr: cleanup main loop and shutdown hook impl
schmichael Jun 29, 2018
6250509
remove unused allocrunner shim
schmichael Jul 11, 2018
370d92f
pass statedb into allocrunnerv2
schmichael Jul 11, 2018
4107afd
reimplement success state for tr hooks and state persistence
schmichael Jul 11, 2018
bfbc95e
fix hclog level
schmichael Jul 11, 2018
d3d590f
tr: fix setting done in existing hooks
schmichael Jul 11, 2018
eea820e
tr: pass context to hooks
schmichael Jul 11, 2018
fdd3bb6
tr: improve skip log line
schmichael Jul 11, 2018
427eab5
vault hook
dadgar Jul 12, 2018
781c498
address comments
dadgar Jul 13, 2018
711d09e
Template hook
dadgar Jul 13, 2018
05a0565
remove comment
dadgar Jul 16, 2018
912d361
Hook renames
dadgar Jul 17, 2018
c19ea97
comments
dadgar Jul 17, 2018
8030341
Implement lifecycle hooks on the task runner
dadgar Jul 16, 2018
7e60f0b
client: implement all-or-nothing alloc restoration
schmichael Jul 13, 2018
457250b
wip split event emitting and state transitions
schmichael Jul 16, 2018
9c04ed3
compile
dadgar Jul 17, 2018
bbcc916
Remove SetState from interface
dadgar Jul 17, 2018
cdabf42
Fix deadlock
dadgar Jul 17, 2018
4f2d641
wip
dadgar Jul 18, 2018
b09b552
missed locking around c.allocs access
schmichael Jul 19, 2018
fae9474
tr: add validate task hook
schmichael Jul 18, 2018
ebf1aa0
Define and thread through state updating interface
dadgar Jul 18, 2018
52ae83d
Update state with server
dadgar Jul 19, 2018
a744845
no need to TaskStateUpdated to return an error
schmichael Jul 19, 2018
3bca947
log before killing tasks
schmichael Jul 19, 2018
bb27389
restore vault client
schmichael Jul 20, 2018
76194c7
consul service hook
schmichael Jul 20, 2018
cea2b87
Add Network method to Handle interface
schmichael Jul 30, 2018
97dbf99
call handle.Network() instead of storing it
schmichael Jul 30, 2018
7ca41a8
Implement alloc updates in arv2
schmichael Aug 1, 2018
8958919
removing old restoration path before api change
schmichael Aug 8, 2018
e8036ff
artifacts: don't emit event when there's no artifacts
schmichael Aug 8, 2018
27894a5
tr: persist hook state whenever it changes
schmichael Aug 8, 2018
63fea0c
implement all boltdb interactions behind StateDB
schmichael Aug 8, 2018
c9e9712
Move all encoding and put deduping into state db
schmichael Aug 9, 2018
e808a1b
wip wrap boltdb to get path information
schmichael Aug 15, 2018
c0d1b63
wrap boltdb in a write deduplicator
schmichael Aug 16, 2018
b97bbd9
persist alloc state on changes, not periodically
schmichael Aug 17, 2018
051c5ea
keep forgetting lxc
schmichael Aug 17, 2018
de54261
lots of comment/log fixes
schmichael Aug 22, 2018
c95155d
implement stopping, destroying, and disk migration
schmichael Aug 23, 2018
9da25ad
client: hclog-ify most of the client
schmichael Aug 29, 2018
12171cd
make AllocBroadcaster easier to use
schmichael Aug 30, 2018
5f668aa
refactor ar hooks into their own files
schmichael Aug 31, 2018
2b5d840
arv2: implement alloc health watching
schmichael Aug 30, 2018
6ba5c7c
fix detection of task transitioning to running
schmichael Sep 7, 2018
bc26540
ar: create health setting shim for health watcher
schmichael Sep 11, 2018
5405313
tr: refactor EmitEvents into Emit+Append
schmichael Sep 11, 2018
0d7b6e7
ar: use multierror in update hook loop
schmichael Sep 11, 2018
61a5a84
Use a semaphore to block until watcher exits
schmichael Sep 11, 2018
15b568c
Emit events before long operations
schmichael Sep 11, 2018
5cbd013
health_hook: fix panic and add tests
schmichael Sep 12, 2018
e9f3f2c
Update runc/libcontainer and friends (#4655)
nickethier Sep 14, 2018
9a2c2a4
client uses passed logger and fix fingerprinters
dadgar Sep 16, 2018
a203689
fifo: add new fifo package for named pipes (#4665)
nickethier Sep 17, 2018
9fd0ba1
add logger back
dadgar Sep 17, 2018
b7d3f59
health_hook: simplify locking; test thoroughly
schmichael Sep 14, 2018
d0842e7
test: cleanup mock consul service client
schmichael Sep 14, 2018
796f0ca
fix build errors post merges
schmichael Sep 18, 2018
da8f053
tr: implement stats collection hook
schmichael Sep 15, 2018
5b14d24
executor v2 (#4656)
nickethier Sep 24, 2018
78c15dc
tr: add comments and cleanup call signature
schmichael Sep 25, 2018
e2bf0a3
clientv2: base driver plugin (#4671)
nickethier Sep 26, 2018
2b655e4
driver/raw_exec: initial raw_exec implementation
nickethier Sep 19, 2018
650ac5a
driver/raw_exec: more tests and bug fixes
nickethier Sep 25, 2018
8f2f603
lint: remove unused code and fix spelling
nickethier Sep 25, 2018
05ca3e9
driver/raw_exec: export driver config fields so they are encoded
nickethier Sep 26, 2018
c9f0d2e
driver/raw_exec: port existing raw_exec tests and add some testing ut…
nickethier Sep 26, 2018
3910057
fix package references after drivers/base subpackage removed
nickethier Sep 26, 2018
50b2981
raw_exec: move package outside of plugins dir
nickethier Sep 26, 2018
fc16a5c
plugin/drivers: plumb in stdout/stderr paths
nickethier Sep 26, 2018
7ad161f
drivers/raw_exec: added unix specific tests
nickethier Sep 26, 2018
757260a
drivers/raw_exec: sync access to task state
nickethier Sep 26, 2018
957ea01
Internal plugin catalog
dadgar Sep 26, 2018
7882ae4
Plugin loader initialization
dadgar Sep 26, 2018
e2553a1
Fix client reloading and pass the plugin loaders to server and client
dadgar Sep 27, 2018
14cc4f7
extra logging
dadgar Sep 27, 2018
1dcde75
ar: lock around accessing tasks
schmichael Sep 20, 2018
95634ae
tr: remove wip comments
schmichael Sep 20, 2018
9394b98
client: fix accessing alloc runners
schmichael Sep 20, 2018
349b827
mock_driver: close waitCh after exiting
schmichael Sep 20, 2018
13f47aa
client: do not inspect task state to follow logs
schmichael Sep 20, 2018
9f64add
tr: fix shutdown/destroy/WaitResult handling
schmichael Sep 20, 2018
334f2b4
tests: fix races caused by sharing a buffer
schmichael Sep 20, 2018
981acf3
tr: remove unneeded lock; chan synchronizes access
schmichael Sep 25, 2018
99e2953
client: fix potentially dropped streaming errors
schmichael Sep 25, 2018
737b1d8
client: add comment
schmichael Sep 25, 2018
d29d613
client: expose task state to client
schmichael Sep 27, 2018
62e90cd
tests: test via ServeMux so http codes are set
schmichael Sep 27, 2018
e495a04
tests: ensure task state is initialized in NewAR
schmichael Sep 27, 2018
01f057e
tests: make a test client/config easier to generate
schmichael Sep 27, 2018
4d1a1ac
tests: test logs endpoint against pending task
schmichael Sep 27, 2018
8e92896
ar: AllocState should not mutate ar.state
schmichael Sep 28, 2018
3b8da30
tr: properly comment handle fields
schmichael Sep 28, 2018
37387bb
tests: fix missing logger caused by bad merge
schmichael Sep 28, 2018
0d7bf53
plugin/drivers: rework eventer and change naming stream -> consumer
nickethier Sep 30, 2018
207522b
drivers/rawexec: PR comments and feedback
nickethier Sep 30, 2018
a8d50e8
plugins/drivers: remove bool to track if eventLoop shutdown and use c…
nickethier Sep 30, 2018
ca27a02
drivers/utils: better handling of consumer cleanup in eventer
nickethier Oct 2, 2018
db981de
drivers/shared: move eventer to subpackage under drivers shared package
nickethier Oct 2, 2018
3f7c14c
drivers/shared: added func comment to eventer
nickethier Oct 3, 2018
2e535ae
move files around
dadgar Oct 4, 2018
31d49c7
skip building deprecated files
dadgar Oct 4, 2018
f91b269
fix test compiling
dadgar Oct 4, 2018
3a492bb
allocrunnerv2 -> allocrunner
dadgar Oct 4, 2018
7b7cb38
more test fixes
dadgar Oct 4, 2018
3c0b073
compile on windows
dadgar Oct 4, 2018
627e208
Fix lints
dadgar Oct 5, 2018
d335a82
client: begin driver plugin integration
nickethier Oct 4, 2018
ea9ed22
client: refactor post allocrunnerv2 finalization
nickethier Oct 6, 2018
dd3b2ef
docklog: add go-plugin for forwarding of docker logs
nickethier Oct 6, 2018
4f9522d
client: review comments and fixup/skip tests
nickethier Oct 10, 2018
d68f2f0
client: fix broked tests from refactoring
nickethier Oct 10, 2018
b016b2b
plugin/driver: add Copy funcs
nickethier Oct 11, 2018
44cc52a
client: simplify driver plugin logic from review comments
nickethier Oct 11, 2018
993e045
taskrunner: return error on waitCh
nickethier Oct 11, 2018
5338103
Get raw exec tests compiling and passing again
preetapan Oct 11, 2018
b751030
rkt: start rkt driver plugin
nickethier Oct 5, 2018
2e055fe
client: add test for driverfailure during fingerprinting
nickethier Oct 11, 2018
19b222b
client: log retry during driver fingerprint redispense
nickethier Oct 11, 2018
0ebc3bd
RKT driver plugin and unit tests
preetapan Oct 12, 2018
04a2aad
Stats collection test
preetapan Oct 12, 2018
3c6d6b9
Review comments
preetapan Oct 15, 2018
f13a094
make port map a slice of maps to match existing rkt driver
preetapan Oct 15, 2018
a44e82f
tr: implement dispatch payload hook
schmichael Oct 10, 2018
2256917
Port client portion of #4392 to new taskrunner
schmichael Oct 10, 2018
9bd696e
drivers/mock: start mock driver implementation
nickethier Oct 12, 2018
089bce5
drivers/mock: complete plugin impl
schmichael Oct 12, 2018
7848acb
register drivers by default
schmichael Oct 15, 2018
4175e90
fixup comments, logging, and missing method impls
schmichael Oct 15, 2018
be57b3e
Switch back to using map[string]string for port map
preetapan Oct 15, 2018
ed2b3b2
Address review comments
preetapan Oct 15, 2018
b12de40
Address review comments around logging task properly
preetapan Oct 15, 2018
2b249ee
plugins: msgpack codec should use cty tags
schmichael Oct 16, 2018
9c4a1d4
drivers/mock: fix plugin name
schmichael Oct 16, 2018
e026d6e
tr: remove unused DriverHandle interface
schmichael Oct 16, 2018
3a9ed23
driver/docker: rename container logger
nickethier Oct 16, 2018
cb19964
client: remove unused handleproxy
schmichael Oct 16, 2018
7ebe701
changelog: add client refactor feature branch merge
schmichael Oct 16, 2018
cf42289
fix linter errors
schmichael Oct 16, 2018
4cf022c
templates: fix tests
schmichael Oct 16, 2018
2361c19
tests: get tests building if not yet passing
schmichael Oct 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## 0.9.0 (Unreleased)

__BACKWARDS INCOMPATIBILITIES:__
* core: Switch to structured logging using [go-hclog](https://github.com/hashicorp/go-hclog)

IMPROVEMENTS:
* core: Added advertise address to client node meta data [[GH-4390](https://github.com/hashicorp/nomad/issues/4390)]
* core: Added support for specifying node affinities. Affinities allow job operators to specify weighted placement preferences
according to different node attributes [[GH-4512](https://github.com/hashicorp/nomad/issues/4512)]
* core: Added support for spreading allocations across a specific attribute. Operators can specify spread
target percentages across failure domains such as datacenter or rack [[GH-4512](https://github.com/hashicorp/nomad/issues/4512)]
* client: Refactor client to support plugins and improve state handling [[GH-4792](https://github.com/hashicorp/nomad/pull/4792)]
* client: Extend timeout to 60 seconds for Windows CPU fingerprinting [[GH-4441](https://github.com/hashicorp/nomad/pull/4441)]
* driver/docker: Add support for specifying `cpu_cfs_period` in the Docker driver [[GH-4462](https://github.com/hashicorp/nomad/issues/4462)]
* telemetry: All client metrics include a new `node_class` tag [[GH-3882](https://github.com/hashicorp/nomad/issues/3882)]
Expand All @@ -15,6 +19,7 @@ IMPROVEMENTS:

BUG FIXES:
* core: Fixed bug in reconciler where allocs already stopped were being unnecessarily updated [[GH-4764](https://github.com/hashicorp/nomad/issues/4764)]
* client: Fix an issue reloading the client config [[GH-4730](https://github.com/hashicorp/nomad/issues/4730)]

## 0.8.6 (September 26, 2018)

Expand Down
4 changes: 2 additions & 2 deletions client/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *Client) resolveTokenValue(secretID string) (*structs.ACLToken, error) {
if err := c.RPC("ACL.ResolveToken", &req, &resp); err != nil {
// If we encounter an error but have a cached value, mask the error and extend the cache
if ok {
c.logger.Printf("[WARN] client: failed to resolve token, using expired cached value: %v", err)
c.logger.Warn("failed to resolve token, using expired cached value", "error", err)
cached := raw.(*cachedACLValue)
return cached.Token, nil
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (c *Client) resolvePolicies(secretID string, policies []string) ([]*structs
if err := c.RPC("ACL.GetPolicies", &req, &resp); err != nil {
// If we encounter an error but have cached policies, mask the error and extend the cache
if len(missing) == 0 {
c.logger.Printf("[WARN] client: failed to resolve policies, using expired cached value: %v", err)
c.logger.Warn("failed to resolve policies, using expired cached value", "error", err)
out = append(out, expired...)
return out, nil
}
Expand Down
2 changes: 2 additions & 0 deletions client/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestAllocations_GarbageCollectAll_ACL(t *testing.T) {
}

func TestAllocations_GarbageCollect(t *testing.T) {
t.Skip("missing mock driver plugin implementation")
t.Parallel()
require := require.New(t)
client := TestClient(t, func(c *config.Config) {
Expand Down Expand Up @@ -174,6 +175,7 @@ func TestAllocations_GarbageCollect_ACL(t *testing.T) {
}

func TestAllocations_Stats(t *testing.T) {
t.Skip("missing exec driver plugin implementation")
t.Parallel()
require := require.New(t)
client := TestClient(t, nil)
Expand Down
1 change: 1 addition & 0 deletions client/alloc_watcher_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// TestPrevAlloc_StreamAllocDir_TLS asserts ephemeral disk migrations still
// work when TLS is enabled.
func TestPrevAlloc_StreamAllocDir_TLS(t *testing.T) {
t.Skip("missing mock driver plugin implementation")
const (
caFn = "../helper/tlsutil/testdata/global-ca.pem"
serverCertFn = "../helper/tlsutil/testdata/global-server.pem"
Expand Down
39 changes: 34 additions & 5 deletions client/allocdir/alloc_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"sync"
"time"

hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -58,6 +59,8 @@ var (
TaskDirs = map[string]os.FileMode{TmpDirName: os.ModeSticky | 0777}
)

// AllocDir allows creating, destroying, and accessing an allocation's
// directory. All methods are safe for concurrent use.
type AllocDir struct {
// AllocDir is the directory used for storing any state
// of this allocation. It will be purged on alloc destroy.
Expand All @@ -73,7 +76,9 @@ type AllocDir struct {
// built is true if Build has successfully run
built bool

logger *log.Logger
mu sync.RWMutex

logger hclog.Logger
}

// AllocDirFS exposes file operations on the alloc dir
Expand All @@ -88,7 +93,8 @@ type AllocDirFS interface {

// NewAllocDir initializes the AllocDir struct with allocDir as base path for
// the allocation directory.
func NewAllocDir(logger *log.Logger, allocDir string) *AllocDir {
func NewAllocDir(logger hclog.Logger, allocDir string) *AllocDir {
logger = logger.Named("alloc_dir")
return &AllocDir{
AllocDir: allocDir,
SharedDir: filepath.Join(allocDir, SharedAllocName),
Expand All @@ -100,6 +106,9 @@ func NewAllocDir(logger *log.Logger, allocDir string) *AllocDir {
// Copy an AllocDir and all of its TaskDirs. Returns nil if AllocDir is
// nil.
func (d *AllocDir) Copy() *AllocDir {
d.mu.RLock()
defer d.mu.RUnlock()

if d == nil {
return nil
}
Expand All @@ -117,6 +126,9 @@ func (d *AllocDir) Copy() *AllocDir {

// NewTaskDir creates a new TaskDir and adds it to the AllocDirs TaskDirs map.
func (d *AllocDir) NewTaskDir(name string) *TaskDir {
d.mu.Lock()
defer d.mu.Unlock()

td := newTaskDir(d.logger, d.AllocDir, name)
d.TaskDirs[name] = td
return td
Expand All @@ -129,6 +141,9 @@ func (d *AllocDir) NewTaskDir(name string) *TaskDir {
// file "NOMAD-${ALLOC_ID}-ERROR.log" will be appended to the tar with the
// error message as the contents.
func (d *AllocDir) Snapshot(w io.Writer) error {
d.mu.RLock()
defer d.mu.RUnlock()

allocDataDir := filepath.Join(d.SharedDir, SharedDataDir)
rootPaths := []string{allocDataDir}
for _, taskdir := range d.TaskDirs {
Expand Down Expand Up @@ -195,7 +210,7 @@ func (d *AllocDir) Snapshot(w io.Writer) error {
// the snapshotting side closed the connect
// prematurely and won't try to use the tar
// anyway.
d.logger.Printf("[WARN] client: snapshotting failed and unable to write error marker: %v", writeErr)
d.logger.Warn("snapshotting failed and unable to write error marker", "error", writeErr)
}
return fmt.Errorf("failed to snapshot %s: %v", path, err)
}
Expand All @@ -206,11 +221,16 @@ func (d *AllocDir) Snapshot(w io.Writer) error {

// Move other alloc directory's shared path and local dir to this alloc dir.
func (d *AllocDir) Move(other *AllocDir, tasks []*structs.Task) error {
d.mu.RLock()
if !d.built {
// Enforce the invariant that Build is called before Move
d.mu.RUnlock()
return fmt.Errorf("unable to move to %q - alloc dir is not built", d.AllocDir)
}

// Moving is slow and only reads immutable fields, so unlock during heavy IO
d.mu.RUnlock()

// Move the data directory
otherDataDir := filepath.Join(other.SharedDir, SharedDataDir)
dataDir := filepath.Join(d.SharedDir, SharedDataDir)
Expand Down Expand Up @@ -246,7 +266,6 @@ func (d *AllocDir) Move(other *AllocDir, tasks []*structs.Task) error {

// Tears down previously build directory structure.
func (d *AllocDir) Destroy() error {

// Unmount all mounted shared alloc dirs.
var mErr multierror.Error
if err := d.UnmountAll(); err != nil {
Expand All @@ -258,12 +277,17 @@ func (d *AllocDir) Destroy() error {
}

// Unset built since the alloc dir has been destroyed.
d.mu.Lock()
d.built = false
d.mu.Unlock()
return mErr.ErrorOrNil()
}

// UnmountAll linked/mounted directories in task dirs.
func (d *AllocDir) UnmountAll() error {
d.mu.RLock()
defer d.mu.RUnlock()

var mErr multierror.Error
for _, dir := range d.TaskDirs {
// Check if the directory has the shared alloc mounted.
Expand Down Expand Up @@ -322,7 +346,9 @@ func (d *AllocDir) Build() error {
}

// Mark as built
d.mu.Lock()
d.built = true
d.mu.Unlock()
return nil
}

Expand Down Expand Up @@ -386,11 +412,14 @@ func (d *AllocDir) ReadAt(path string, offset int64) (io.ReadCloser, error) {
p := filepath.Join(d.AllocDir, path)

// Check if it is trying to read into a secret directory
d.mu.RLock()
for _, dir := range d.TaskDirs {
if filepath.HasPrefix(p, dir.SecretsDir) {
d.mu.RUnlock()
return nil, fmt.Errorf("Reading secret file prohibited: %s", path)
}
}
d.mu.RUnlock()

f, err := os.Open(p)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions client/allocdir/alloc_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestAllocDir_BuildAlloc(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
d.NewTaskDir(t1.Name)
d.NewTaskDir(t2.Name)
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestAllocDir_MountSharedAlloc(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
if err := d.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestAllocDir_Snapshot(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
if err := d.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
Expand Down Expand Up @@ -223,13 +223,13 @@ func TestAllocDir_Move(t *testing.T) {
defer os.RemoveAll(tmp2)

// Create two alloc dirs
d1 := NewAllocDir(testlog.Logger(t), tmp1)
d1 := NewAllocDir(testlog.HCLogger(t), tmp1)
if err := d1.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
}
defer d1.Destroy()

d2 := NewAllocDir(testlog.Logger(t), tmp2)
d2 := NewAllocDir(testlog.HCLogger(t), tmp2)
if err := d2.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestAllocDir_EscapeChecking(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
if err := d.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestAllocDir_ReadAt_SecretDir(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
if err := d.Build(); err != nil {
t.Fatalf("Build() failed: %v", err)
}
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestAllocDir_CreateDir(t *testing.T) {
// TestAllocDir_Copy asserts that AllocDir.Copy does a deep copy of itself and
// all TaskDirs.
func TestAllocDir_Copy(t *testing.T) {
a := NewAllocDir(testlog.Logger(t), "foo")
a := NewAllocDir(testlog.HCLogger(t), "foo")
a.NewTaskDir("bar")
a.NewTaskDir("baz")

Expand Down
13 changes: 10 additions & 3 deletions client/allocdir/task_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package allocdir
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

hclog "github.com/hashicorp/go-hclog"
cstructs "github.com/hashicorp/nomad/client/structs"
)

// TaskDir contains all of the paths relevant to a task. All paths are on the
// host system so drivers should mount/link into task containers as necessary.
type TaskDir struct {
// AllocDir is the path to the alloc directory on the host
AllocDir string

// Dir is the path to Task directory on the host
Dir string

Expand All @@ -37,16 +40,20 @@ type TaskDir struct {
// <task_dir>/secrets/
SecretsDir string

logger *log.Logger
logger hclog.Logger
}

// newTaskDir creates a TaskDir struct with paths set. Call Build() to
// create paths on disk.
//
// Call AllocDir.NewTaskDir to create new TaskDirs
func newTaskDir(logger *log.Logger, allocDir, taskName string) *TaskDir {
func newTaskDir(logger hclog.Logger, allocDir, taskName string) *TaskDir {
taskDir := filepath.Join(allocDir, taskName)

logger = logger.Named("task_dir").With("task_name", taskName)

return &TaskDir{
AllocDir: allocDir,
Dir: taskDir,
SharedAllocDir: filepath.Join(allocDir, SharedAllocName),
LogDir: filepath.Join(allocDir, SharedAllocName, LogDirName),
Expand Down
2 changes: 1 addition & 1 deletion client/allocdir/task_dir_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestLinuxSpecialDirs(t *testing.T) {
}
defer os.RemoveAll(allocDir)

td := newTaskDir(testlog.Logger(t), allocDir, "test")
td := newTaskDir(testlog.HCLogger(t), allocDir, "test")

// Despite the task dir not existing, unmountSpecialDirs should *not*
// return an error
Expand Down
8 changes: 4 additions & 4 deletions client/allocdir/task_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestTaskDir_EmbedNonexistent(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
td := d.NewTaskDir(t1.Name)
if err := d.Build(); err != nil {
Expand All @@ -40,7 +40,7 @@ func TestTaskDir_EmbedDirs(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
td := d.NewTaskDir(t1.Name)
if err := d.Build(); err != nil {
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestTaskDir_NonRoot_Image(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
td := d.NewTaskDir(t1.Name)
if err := d.Build(); err != nil {
Expand All @@ -120,7 +120,7 @@ func TestTaskDir_NonRoot(t *testing.T) {
}
defer os.RemoveAll(tmp)

d := NewAllocDir(testlog.Logger(t), tmp)
d := NewAllocDir(testlog.HCLogger(t), tmp)
defer d.Destroy()
td := d.NewTaskDir(t1.Name)
if err := d.Build(); err != nil {
Expand Down
Loading