allocdir

package
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2019 License: MPL-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SnapshotErrorTime is the sentinel time that will be used on the
	// error file written by Snapshot when it encounters as error.
	SnapshotErrorTime = time.Date(2000, 0, 0, 0, 0, 0, 0, time.UTC)

	// The name of the directory that is shared across tasks in a task group.
	SharedAllocName = "alloc"

	// Name of the directory where logs of Tasks are written
	LogDirName = "logs"

	// SharedDataDir is one of the shared allocation directories. It is
	// included in snapshots.
	SharedDataDir = "data"

	// TmpDirName is the name of the temporary directory in each alloc and
	// task.
	TmpDirName = "tmp"

	// The set of directories that exist inside each shared alloc directory.
	SharedAllocDirs = []string{LogDirName, TmpDirName, SharedDataDir}

	// The name of the directory that exists inside each task directory
	// regardless of driver.
	TaskLocal = "local"

	// TaskSecrets is the name of the secret directory inside each task
	// directory
	TaskSecrets = "secrets"

	// TaskDirs is the set of directories created in each tasks directory.
	TaskDirs = map[string]os.FileMode{TmpDirName: os.ModeSticky | 0777}
)
View Source
var (
	// SharedAllocContainerPath is the path inside container for mounted
	// directory shared across tasks in a task group.
	SharedAllocContainerPath = filepath.Join("/", SharedAllocName)

	// TaskLocalContainer is the path inside a container for mounted directory
	// for local storage.
	TaskLocalContainerPath = filepath.Join("/", TaskLocal)

	// TaskSecretsContainerPath is the path inside a container for mounted
	// secrets directory
	TaskSecretsContainerPath = filepath.Join("/", TaskSecrets)
)

Functions

func SnapshotErrorFilename added in v0.7.1

func SnapshotErrorFilename(allocID string) string

SnapshotErrorFilename returns the filename which will exist if there was an error snapshotting a tar.

Types

type AllocDir

type AllocDir struct {
	// AllocDir is the directory used for storing any state
	// of this allocation. It will be purged on alloc destroy.
	AllocDir string

	// The shared directory is available to all tasks within the same task
	// group.
	SharedDir string

	// TaskDirs is a mapping of task names to their non-shared directory.
	TaskDirs map[string]*TaskDir
	// contains filtered or unexported fields
}

AllocDir allows creating, destroying, and accessing an allocation's directory. All methods are safe for concurrent use.

func NewAllocDir

func NewAllocDir(logger hclog.Logger, allocDir string) *AllocDir

NewAllocDir initializes the AllocDir struct with allocDir as base path for the allocation directory.

func (*AllocDir) BlockUntilExists added in v0.4.1

func (d *AllocDir) BlockUntilExists(ctx context.Context, path string) (chan error, error)

BlockUntilExists blocks until the passed file relative the allocation directory exists. The block can be cancelled with the passed context.

func (*AllocDir) Build

func (d *AllocDir) Build() error

Build the directory tree for an allocation.

func (*AllocDir) ChangeEvents added in v0.4.1

func (d *AllocDir) ChangeEvents(ctx context.Context, path string, curOffset int64) (*watch.FileChanges, error)

ChangeEvents watches for changes to the passed path relative to the allocation directory. The offset should be the last read offset. The context is used to clean up the watch.

func (*AllocDir) Copy added in v0.6.0

func (d *AllocDir) Copy() *AllocDir

Copy an AllocDir and all of its TaskDirs. Returns nil if AllocDir is nil.

func (*AllocDir) Destroy

func (d *AllocDir) Destroy() error

Tears down previously build directory structure.

func (*AllocDir) List added in v0.3.0

func (d *AllocDir) List(path string) ([]*cstructs.AllocFileInfo, error)

List returns the list of files at a path relative to the alloc dir

func (*AllocDir) Move added in v0.5.0

func (d *AllocDir) Move(other *AllocDir, tasks []*structs.Task) error

Move other alloc directory's shared path and local dir to this alloc dir.

func (*AllocDir) NewTaskDir added in v0.5.3

func (d *AllocDir) NewTaskDir(name string) *TaskDir

NewTaskDir creates a new TaskDir and adds it to the AllocDirs TaskDirs map.

func (*AllocDir) ReadAt added in v0.3.0

func (d *AllocDir) ReadAt(path string, offset int64) (io.ReadCloser, error)

ReadAt returns a reader for a file at the path relative to the alloc dir

func (*AllocDir) Snapshot added in v0.5.0

func (d *AllocDir) Snapshot(w io.Writer) error

Snapshot creates an archive of the files and directories in the data dir of the allocation and the task local directories

Since a valid tar may have been written even when an error occurs, a special file "NOMAD-${ALLOC_ID}-ERROR.log" will be appended to the tar with the error message as the contents.

func (*AllocDir) Stat added in v0.3.0

func (d *AllocDir) Stat(path string) (*cstructs.AllocFileInfo, error)

Stat returns information about the file at a path relative to the alloc dir

func (*AllocDir) UnmountAll added in v0.3.0

func (d *AllocDir) UnmountAll() error

UnmountAll linked/mounted directories in task dirs.

type AllocDirFS added in v0.3.0

type AllocDirFS interface {
	List(path string) ([]*cstructs.AllocFileInfo, error)
	Stat(path string) (*cstructs.AllocFileInfo, error)
	ReadAt(path string, offset int64) (io.ReadCloser, error)
	Snapshot(w io.Writer) error
	BlockUntilExists(ctx context.Context, path string) (chan error, error)
	ChangeEvents(ctx context.Context, path string, curOffset int64) (*watch.FileChanges, error)
}

AllocDirFS exposes file operations on the alloc dir

type TaskDir added in v0.5.3

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

	// SharedAllocDir is the path to shared alloc directory on the host
	// <alloc_dir>/alloc/
	SharedAllocDir string

	// SharedTaskDir is the path to the shared alloc directory linked into
	// the task directory on the host.
	// <task_dir>/alloc/
	SharedTaskDir string

	// LocalDir is the path to the task's local directory on the host
	// <task_dir>/local/
	LocalDir string

	// LogDir is the path to the task's log directory on the host
	// <alloc_dir>/alloc/logs/
	LogDir string

	// SecretsDir is the path to secrets/ directory on the host
	// <task_dir>/secrets/
	SecretsDir string
	// contains filtered or unexported fields
}

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.

func (*TaskDir) Build added in v0.5.3

func (t *TaskDir) Build(createChroot bool, chroot map[string]string) error

Build default directories and permissions in a task directory. chrootCreated allows skipping chroot creation if the caller knows it has already been done.

func (*TaskDir) Copy added in v0.6.0

func (t *TaskDir) Copy() *TaskDir

Copy a TaskDir. Panics if TaskDir is nil as TaskDirs should never be nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL