mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
add job and task group meta
This commit is contained in:
@@ -121,8 +121,11 @@ func NewExecContext(alloc *allocdir.AllocDir, allocID string) *ExecContext {
|
||||
func GetTaskEnv(allocDir *allocdir.AllocDir, node *structs.Node,
|
||||
task *structs.Task, alloc *structs.Allocation) (*env.TaskEnvironment, error) {
|
||||
|
||||
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
|
||||
env := env.NewTaskEnvironment(node).
|
||||
SetMeta(task.Meta).
|
||||
SetTaskMeta(task.Meta).
|
||||
SetTaskGroupMeta(tg.Meta).
|
||||
SetJobMeta(alloc.Job.Meta).
|
||||
SetEnvvars(task.Env).
|
||||
SetTaskName(task.Name)
|
||||
|
||||
|
||||
64
client/driver/env/env.go
vendored
64
client/driver/env/env.go
vendored
@@ -67,19 +67,21 @@ const (
|
||||
// TaskEnvironment is used to expose information to a task via environment
|
||||
// variables and provide interpolation of Nomad variables.
|
||||
type TaskEnvironment struct {
|
||||
Env map[string]string
|
||||
Meta map[string]string
|
||||
AllocDir string
|
||||
TaskDir string
|
||||
CpuLimit int
|
||||
MemLimit int
|
||||
TaskName string
|
||||
AllocIndex int
|
||||
AllocId string
|
||||
AllocName string
|
||||
Node *structs.Node
|
||||
Networks []*structs.NetworkResource
|
||||
PortMap map[string]int
|
||||
Env map[string]string
|
||||
TaskMeta map[string]string
|
||||
TaskGroupMeta map[string]string
|
||||
JobMeta map[string]string
|
||||
AllocDir string
|
||||
TaskDir string
|
||||
CpuLimit int
|
||||
MemLimit int
|
||||
TaskName string
|
||||
AllocIndex int
|
||||
AllocId string
|
||||
AllocName string
|
||||
Node *structs.Node
|
||||
Networks []*structs.NetworkResource
|
||||
PortMap map[string]int
|
||||
|
||||
// taskEnv is the variables that will be set in the tasks environment
|
||||
TaskEnv map[string]string
|
||||
@@ -116,9 +118,11 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
|
||||
t.NodeValues = make(map[string]string)
|
||||
t.TaskEnv = make(map[string]string)
|
||||
|
||||
// Build the task metadata
|
||||
for k, v := range t.Meta {
|
||||
t.TaskEnv[fmt.Sprintf("%s%s", MetaPrefix, strings.ToUpper(k))] = v
|
||||
// Build the meta with the following precedence: task, task group, job.
|
||||
for _, meta := range []map[string]string{t.JobMeta, t.TaskGroupMeta, t.TaskMeta} {
|
||||
for k, v := range meta {
|
||||
t.TaskEnv[fmt.Sprintf("%s%s", MetaPrefix, strings.ToUpper(k))] = v
|
||||
}
|
||||
}
|
||||
|
||||
// Build the ports
|
||||
@@ -279,13 +283,33 @@ func (t *TaskEnvironment) clearPortMap() *TaskEnvironment {
|
||||
|
||||
// Takes a map of meta values to be passed to the task. The keys are capatilized
|
||||
// when the environent variable is set.
|
||||
func (t *TaskEnvironment) SetMeta(m map[string]string) *TaskEnvironment {
|
||||
t.Meta = m
|
||||
func (t *TaskEnvironment) SetTaskMeta(m map[string]string) *TaskEnvironment {
|
||||
t.TaskMeta = m
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) ClearMeta() *TaskEnvironment {
|
||||
t.Meta = nil
|
||||
func (t *TaskEnvironment) ClearTaskMeta() *TaskEnvironment {
|
||||
t.TaskMeta = nil
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) SetTaskGroupMeta(m map[string]string) *TaskEnvironment {
|
||||
t.TaskGroupMeta = m
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) ClearTaskGroupMeta() *TaskEnvironment {
|
||||
t.TaskGroupMeta = nil
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) SetJobMeta(m map[string]string) *TaskEnvironment {
|
||||
t.JobMeta = m
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) ClearJobMeta() *TaskEnvironment {
|
||||
t.JobMeta = nil
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user