taskenv

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllocDir is the environment variable with the path to the alloc directory
	// that is shared across tasks within a task group.
	AllocDir = "NOMAD_ALLOC_DIR"

	// TaskLocalDir is the environment variable with the path to the tasks local
	// directory where it can store data that is persisted to the alloc is
	// removed.
	TaskLocalDir = "NOMAD_TASK_DIR"

	// SecretsDir is the environment variable with the path to the tasks secret
	// directory where it can store sensitive data.
	SecretsDir = "NOMAD_SECRETS_DIR"

	// MemLimit is the environment variable with the tasks memory limit in MBs.
	MemLimit = "NOMAD_MEMORY_LIMIT"

	// CpuLimit is the environment variable with the tasks CPU limit in MHz.
	CpuLimit = "NOMAD_CPU_LIMIT"

	// AllocID is the environment variable for passing the allocation ID.
	AllocID = "NOMAD_ALLOC_ID"

	// AllocName is the environment variable for passing the allocation name.
	AllocName = "NOMAD_ALLOC_NAME"

	// TaskName is the environment variable for passing the task name.
	TaskName = "NOMAD_TASK_NAME"

	// GroupName is the environment variable for passing the task group name.
	GroupName = "NOMAD_GROUP_NAME"

	// JobName is the environment variable for passing the job name.
	JobName = "NOMAD_JOB_NAME"

	// AllocIndex is the environment variable for passing the allocation index.
	AllocIndex = "NOMAD_ALLOC_INDEX"

	// Datacenter is the environment variable for passing the datacenter in which the alloc is running.
	Datacenter = "NOMAD_DC"

	// Region is the environment variable for passing the region in which the alloc is running.
	Region = "NOMAD_REGION"

	// AddrPrefix is the prefix for passing both dynamic and static port
	// allocations to tasks.
	// E.g $NOMAD_ADDR_http=127.0.0.1:80
	//
	// The ip:port are always the host's.
	AddrPrefix = "NOMAD_ADDR_"

	// IpPrefix is the prefix for passing the host IP of a port allocation
	// to a task.
	IpPrefix = "NOMAD_IP_"

	// PortPrefix is the prefix for passing the port allocation to a task.
	// It will be the task's port if a port map is specified. Task's should
	// bind to this port.
	PortPrefix = "NOMAD_PORT_"

	// HostPortPrefix is the prefix for passing the host port when a port
	// map is specified.
	HostPortPrefix = "NOMAD_HOST_PORT_"

	// MetaPrefix is the prefix for passing task meta data.
	MetaPrefix = "NOMAD_META_"

	// VaultToken is the environment variable for passing the Vault token
	VaultToken = "VAULT_TOKEN"

	// VaultNamespace is the environment variable for passing the Vault namespace, if applicable
	VaultNamespace = "VAULT_NAMESPACE"
)

A set of environment variables that are exported by each driver.

Variables

View Source
var (
	// ErrInvalidObjectPath is returned when a key cannot be converted into
	// a nested object path like "foo...bar", ".foo", or "foo."
	ErrInvalidObjectPath = errors.New("invalid object path")
)

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is used to build task environment's and is safe for concurrent use.

func NewBuilder

func NewBuilder(node *structs.Node, alloc *structs.Allocation, task *structs.Task, region string) *Builder

NewBuilder creates a new task environment builder.

func NewEmptyBuilder

func NewEmptyBuilder() *Builder

NewEmptyBuilder creates a new environment builder.

func (*Builder) Build

func (b *Builder) Build() *TaskEnv

Build must be called after all the tasks environment values have been set.

func (*Builder) SetAllocDir

func (b *Builder) SetAllocDir(dir string) *Builder

func (*Builder) SetDeviceHookEnv

func (b *Builder) SetDeviceHookEnv(hookName string, envs map[string]string) *Builder

SetDeviceHookEnv sets environment variables from a device hook. Variables are Last-Write-Wins, so if a hook writes a variable that's also written by a later hook, the later hooks value always gets used.

func (*Builder) SetDriverNetwork

func (b *Builder) SetDriverNetwork(n *drivers.DriverNetwork) *Builder

SetDriverNetwork defined by the driver.

func (*Builder) SetHookEnv

func (b *Builder) SetHookEnv(hook string, envs map[string]string) *Builder

SetHookEnv sets environment variables from a hook. Variables are Last-Write-Wins, so if a hook writes a variable that's also written by a later hook, the later hooks value always gets used.

func (*Builder) SetHostEnvvars

func (b *Builder) SetHostEnvvars(filter []string) *Builder

SetHostEnvvars adds the host environment variables to the tasks. The filter parameter can be use to filter host environment from entering the tasks.

func (*Builder) SetSecretsDir

func (b *Builder) SetSecretsDir(dir string) *Builder

func (*Builder) SetTaskLocalDir

func (b *Builder) SetTaskLocalDir(dir string) *Builder

func (*Builder) SetTemplateEnv

func (b *Builder) SetTemplateEnv(m map[string]string) *Builder

func (*Builder) SetVaultToken

func (b *Builder) SetVaultToken(token, namespace string, inject bool) *Builder

func (*Builder) UpdateTask

func (b *Builder) UpdateTask(alloc *structs.Allocation, task *structs.Task) *Builder

Update task updates the environment based on a new alloc and task.

type TaskEnv

type TaskEnv struct {
	// NodeAttrs is the map of node attributes for interpolation
	NodeAttrs map[string]string

	// EnvMap is the map of environment variables
	EnvMap map[string]string
	// contains filtered or unexported fields
}

TaskEnv is a task's environment as well as node attribute's for interpolation.

func NewEmptyTaskEnv

func NewEmptyTaskEnv() *TaskEnv

NewEmptyTaskEnv creates a new empty task environment.

func NewTaskEnv

func NewTaskEnv(env, deviceEnv, node map[string]string) *TaskEnv

NewTaskEnv creates a new task environment with the given environment, device environment and node attribute maps.

func (*TaskEnv) All

func (t *TaskEnv) All() map[string]string

All of the task's environment variables and the node's attributes in a single map.

func (*TaskEnv) AllValues

func (t *TaskEnv) AllValues() (map[string]cty.Value, map[string]error, error)

AllValues is a map of the task's environment variables and the node's attributes with cty.Value (String) values. Errors including keys are returned in a map by key name.

In the rare case of a fatal error, only an error value is returned. This is likely a programming error as user input should not be able to cause a fatal error.

func (*TaskEnv) DeviceEnv

func (t *TaskEnv) DeviceEnv() map[string]string

DeviceEnv returns the task's environment variables set by device hooks.

func (*TaskEnv) List

func (t *TaskEnv) List() []string

List returns the task's environment as a slice of NAME=value pair strings.

func (*TaskEnv) Map

func (t *TaskEnv) Map() map[string]string

Map of the task's environment variables.

func (*TaskEnv) ParseAndReplace

func (t *TaskEnv) ParseAndReplace(args []string) []string

ParseAndReplace takes the user supplied args replaces any instance of an environment variable or Nomad variable in the args with the actual value.

func (*TaskEnv) ReplaceEnv

func (t *TaskEnv) ReplaceEnv(arg string) string

ReplaceEnv takes an arg and replaces all occurrences of environment variables and Nomad variables. If the variable is found in the passed map it is replaced, otherwise the original string is returned.

Jump to

Keyboard shortcuts

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