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

client: add NOMAD_SHORT_ALLOC_ID allocation env var. #12603

Merged
merged 2 commits into from
Apr 20, 2022
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
3 changes: 3 additions & 0 deletions .changelog/12603.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
client: Added `NOMAD_SHORT_ALLOC_ID` allocation env var
```
5 changes: 5 additions & 0 deletions client/taskenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const (
// AllocID is the environment variable for passing the allocation ID.
AllocID = "NOMAD_ALLOC_ID"

// ShortAllocID is the environment variable for passing the short version
// of the allocation ID.
ShortAllocID = "NOMAD_SHORT_ALLOC_ID"

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

Expand Down Expand Up @@ -505,6 +509,7 @@ func (b *Builder) buildEnv(allocDir, localDir, secretsDir string,
// Add the task metadata
if b.allocId != "" {
envMap[AllocID] = b.allocId
envMap[ShortAllocID] = b.allocId[:8]
}
if b.allocName != "" {
envMap[AllocName] = b.allocName
Expand Down
2 changes: 2 additions & 0 deletions client/taskenv/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_JOB_NAME=my-job",
fmt.Sprintf("NOMAD_JOB_PARENT_ID=%s", a.Job.ParentID),
fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID),
fmt.Sprintf("NOMAD_SHORT_ALLOC_ID=%s", a.ID[:8]),
"NOMAD_ALLOC_INDEX=0",
}
sort.Strings(act)
Expand Down Expand Up @@ -404,6 +405,7 @@ func TestEnvironment_AllValues(t *testing.T) {
"NOMAD_JOB_NAME": "my-job",
"NOMAD_JOB_PARENT_ID": a.Job.ParentID,
"NOMAD_ALLOC_ID": a.ID,
"NOMAD_SHORT_ALLOC_ID": a.ID[:8],
"NOMAD_ALLOC_INDEX": "0",
"NOMAD_PORT_connect_proxy_testconnect": "9999",
"NOMAD_HOST_PORT_connect_proxy_testconnect": "9999",
Expand Down
10 changes: 8 additions & 2 deletions website/content/partials/envvars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
</td>
<td>Allocation ID of the task</td>
</tr>
<tr>
<td>
<code>NOMAD_SHORT_ALLOC_ID</code>
</td>
<td>The first 8 characters of the allocation ID of the task</td>
</tr>
<tr>
<td>
<code>NOMAD_ALLOC_NAME</code>
Expand Down Expand Up @@ -166,7 +172,7 @@
</td>
</tr>
<tr>
<th colspan="2">Network-related Variables</th>
<th colSpan="2">Network-related Variables</th>
</tr>
<tr>
<td>
Expand Down Expand Up @@ -300,7 +306,7 @@
</td>
</tr>
<tr>
<th colspan="2">Consul-related Variables (only set for connect native tasks)</th>
<th colSpan="2">Consul-related Variables (only set for connect native tasks)</th>
</tr>
<tr>
<td>
Expand Down