Documentation ¶
Index ¶
- Constants
- Variables
- func InterpolateServices(taskEnv *TaskEnv, services []*structs.Service) []*structs.Service
- func SetPortMapEnvs(envs map[string]string, ports map[string]int) map[string]string
- type Builder
- func (b *Builder) Build() *TaskEnv
- func (b *Builder) SetAllocDir(dir string) *Builder
- func (b *Builder) SetDeviceHookEnv(hookName string, envs map[string]string) *Builder
- func (b *Builder) SetDriverNetwork(n *drivers.DriverNetwork) *Builder
- func (b *Builder) SetHookEnv(hook string, envs map[string]string) *Builder
- func (b *Builder) SetHostEnvvars(filter []string) *Builder
- func (b *Builder) SetSecretsDir(dir string) *Builder
- func (b *Builder) SetTaskLocalDir(dir string) *Builder
- func (b *Builder) SetTemplateEnv(m map[string]string) *Builder
- func (b *Builder) SetUpstreams(upstreams []structs.ConsulUpstream) *Builder
- func (b *Builder) SetVaultToken(token, namespace string, inject bool) *Builder
- func (b *Builder) UpdateTask(alloc *structs.Allocation, task *structs.Task) *Builder
- type TaskEnv
- func (t *TaskEnv) All() map[string]string
- func (t *TaskEnv) AllValues() (map[string]cty.Value, map[string]error, error)
- func (t *TaskEnv) DeviceEnv() map[string]string
- func (t *TaskEnv) List() []string
- func (t *TaskEnv) Map() map[string]string
- func (t *TaskEnv) ParseAndReplace(args []string) []string
- func (t *TaskEnv) ReplaceEnv(arg string) string
Constants ¶
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" // Namespace is the environment variable for passing the namespace in which the alloc is running. Namespace = "NOMAD_NAMESPACE" // 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_" // UpstreamPrefix is the prefix for passing upstream IP and ports to the alloc UpstreamPrefix = "NOMAD_UPSTREAM_" // 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 ¶
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 ¶
func InterpolateServices ¶ added in v0.10.4
InterpolateServices returns an interpolated copy of services and checks with values from the task's environment.
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) SetAllocDir ¶
func (*Builder) SetDeviceHookEnv ¶
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 ¶
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 ¶
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 (*Builder) SetTaskLocalDir ¶
func (*Builder) SetUpstreams ¶ added in v0.10.4
func (b *Builder) SetUpstreams(upstreams []structs.ConsulUpstream) *Builder
SetUpstreams defined by connect enabled group services
func (*Builder) SetVaultToken ¶
func (*Builder) UpdateTask ¶
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 ¶
NewTaskEnv creates a new task environment with the given environment, device environment and node attribute maps.
func (*TaskEnv) All ¶
All of the task's environment variables and the node's attributes in a single map.
func (*TaskEnv) AllValues ¶
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) ParseAndReplace ¶
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 ¶
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.