client: add NOMAD_SHORT_ALLOC_ID allocation env var. (#12603)
This commit is contained in:
parent
c4d92205b4
commit
42068f8823
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
client: Added `NOMAD_SHORT_ALLOC_ID` allocation env var
|
||||||
|
```
|
|
@ -47,6 +47,10 @@ const (
|
||||||
// AllocID is the environment variable for passing the allocation ID.
|
// AllocID is the environment variable for passing the allocation ID.
|
||||||
AllocID = "NOMAD_ALLOC_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 is the environment variable for passing the allocation name.
|
||||||
AllocName = "NOMAD_ALLOC_NAME"
|
AllocName = "NOMAD_ALLOC_NAME"
|
||||||
|
|
||||||
|
@ -505,6 +509,7 @@ func (b *Builder) buildEnv(allocDir, localDir, secretsDir string,
|
||||||
// Add the task metadata
|
// Add the task metadata
|
||||||
if b.allocId != "" {
|
if b.allocId != "" {
|
||||||
envMap[AllocID] = b.allocId
|
envMap[AllocID] = b.allocId
|
||||||
|
envMap[ShortAllocID] = b.allocId[:8]
|
||||||
}
|
}
|
||||||
if b.allocName != "" {
|
if b.allocName != "" {
|
||||||
envMap[AllocName] = b.allocName
|
envMap[AllocName] = b.allocName
|
||||||
|
|
|
@ -238,6 +238,7 @@ func TestEnvironment_AsList(t *testing.T) {
|
||||||
"NOMAD_JOB_NAME=my-job",
|
"NOMAD_JOB_NAME=my-job",
|
||||||
fmt.Sprintf("NOMAD_JOB_PARENT_ID=%s", a.Job.ParentID),
|
fmt.Sprintf("NOMAD_JOB_PARENT_ID=%s", a.Job.ParentID),
|
||||||
fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID),
|
fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID),
|
||||||
|
fmt.Sprintf("NOMAD_SHORT_ALLOC_ID=%s", a.ID[:8]),
|
||||||
"NOMAD_ALLOC_INDEX=0",
|
"NOMAD_ALLOC_INDEX=0",
|
||||||
}
|
}
|
||||||
sort.Strings(act)
|
sort.Strings(act)
|
||||||
|
@ -404,6 +405,7 @@ func TestEnvironment_AllValues(t *testing.T) {
|
||||||
"NOMAD_JOB_NAME": "my-job",
|
"NOMAD_JOB_NAME": "my-job",
|
||||||
"NOMAD_JOB_PARENT_ID": a.Job.ParentID,
|
"NOMAD_JOB_PARENT_ID": a.Job.ParentID,
|
||||||
"NOMAD_ALLOC_ID": a.ID,
|
"NOMAD_ALLOC_ID": a.ID,
|
||||||
|
"NOMAD_SHORT_ALLOC_ID": a.ID[:8],
|
||||||
"NOMAD_ALLOC_INDEX": "0",
|
"NOMAD_ALLOC_INDEX": "0",
|
||||||
"NOMAD_PORT_connect_proxy_testconnect": "9999",
|
"NOMAD_PORT_connect_proxy_testconnect": "9999",
|
||||||
"NOMAD_HOST_PORT_connect_proxy_testconnect": "9999",
|
"NOMAD_HOST_PORT_connect_proxy_testconnect": "9999",
|
||||||
|
|
|
@ -69,6 +69,12 @@
|
||||||
</td>
|
</td>
|
||||||
<td>Allocation ID of the task</td>
|
<td>Allocation ID of the task</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<code>NOMAD_ALLOC_NAME</code>
|
<code>NOMAD_ALLOC_NAME</code>
|
||||||
|
@ -166,7 +172,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Network-related Variables</th>
|
<th colSpan="2">Network-related Variables</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
@ -300,7 +306,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<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>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
Loading…
Reference in New Issue