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

Pass task group name as NOMAD_GROUP_NAME environment variable #2877

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func setupTaskEnv(t *testing.T, driver string) (*allocdir.TaskDir, map[string]st
"NOMAD_ALLOC_INDEX": "0",
"NOMAD_ALLOC_NAME": alloc.Name,
"NOMAD_TASK_NAME": task.Name,
"NOMAD_GROUP_NAME": alloc.TaskGroup,
"NOMAD_JOB_NAME": alloc.Job.Name,
"NOMAD_DC": "dc1",
"NOMAD_REGION": "global",
Expand Down
8 changes: 8 additions & 0 deletions client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const (
// 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"

Expand Down Expand Up @@ -208,6 +211,7 @@ type Builder struct {
region string
allocId string
allocName string
groupName string
vaultToken string
injectVaultToken bool
jobName string
Expand Down Expand Up @@ -277,6 +281,9 @@ func (b *Builder) Build() *TaskEnv {
if b.allocName != "" {
envMap[AllocName] = b.allocName
}
if b.groupName != "" {
envMap[GroupName] = b.groupName
}
if b.allocIndex != -1 {
envMap[AllocIndex] = strconv.Itoa(b.allocIndex)
}
Expand Down Expand Up @@ -380,6 +387,7 @@ func (b *Builder) setTask(task *structs.Task) *Builder {
func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder {
b.allocId = alloc.ID
b.allocName = alloc.Name
b.groupName = alloc.TaskGroup
b.allocIndex = int(alloc.Index())
b.jobName = alloc.Job.Name

Expand Down
1 change: 1 addition & 0 deletions client/driver/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_HOST_PORT_http=80",
"NOMAD_HOST_PORT_https=8080",
"NOMAD_TASK_NAME=web",
"NOMAD_GROUP_NAME=web",
"NOMAD_ADDR_ssh_other=192.168.0.100:1234",
"NOMAD_ADDR_ssh_ssh=192.168.0.100:22",
"NOMAD_IP_ssh_other=192.168.0.100",
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/runtime/_envvars.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<td><tt>NOMAD_TASK_NAME</tt></td>
<td>Task's name</td>
</tr>
<tr>
<td><tt>NOMAD_GROUP_NAME</tt></td>
<td>Group's name</td>
</tr>
<tr>
<td><tt>NOMAD_JOB_NAME</tt></td>
<td>Job's name</td>
Expand Down
10 changes: 5 additions & 5 deletions website/source/docs/runtime/environment.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ environment variable names such as `NOMAD_ADDR_<task>_<label>`.

## Task Identifiers

Nomad will pass both the allocation ID and name as well as the task and job's
names. These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`,
`NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, and `NOMAD_TASK_NAME`. The allocation ID
and index can be useful when the task being run needs a unique identifier or to
know its instance count.
Nomad will pass both the allocation ID and name as well as the task, group and
job's names. These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`,
`NOMAD_ALLOC_INDEX`, `NOMAD_JOB_NAME`, `NOMAD_GROUP_NAME` and `NOMAD_TASK_NAME`.
The allocation ID and index can be useful when the task being run needs a unique
identifier or to know its instance count.

## Resources

Expand Down