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

Add NOMAD_{IP,PORT}_<task>_<label> env vars #2426

Merged
merged 2 commits into from
Mar 13, 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ IMPROVEMENTS:
* client: Don't exec `uname -r` for node attribute kernel.version [GH-2380]
* client: Artifact support for git and hg as well as netrc support [GH-2386]
* client: Add metrics to show number of allocations on in each state [GH-2425]
* client: Add `NOMAD_{IP,PORT}_<task>_<label>` environment variables [GH-2426]
* client: Reproducible Node ID on OSes that provide system-level UUID
[GH-2277]
* driver/docker: Add support for volume drivers [GH-2351]
Expand Down
6 changes: 5 additions & 1 deletion client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (

// AddrPrefix is the prefix for passing both dynamic and static port
// allocations to tasks.
// E.g$NOMAD_ADDR_http=127.0.0.1:80
// E.g $NOMAD_ADDR_http=127.0.0.1:80
AddrPrefix = "NOMAD_ADDR_"

// IpPrefix is the prefix for passing the IP of a port allocation to a task.
Expand Down Expand Up @@ -213,6 +213,10 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
for _, p := range ports {
key := fmt.Sprintf("%s%s_%s", AddrPrefix, taskName, p.Label)
t.TaskEnv[key] = fmt.Sprintf("%s:%d", nw.IP, p.Value)
key = fmt.Sprintf("%s%s_%s", IpPrefix, taskName, p.Label)
t.TaskEnv[key] = nw.IP
key = fmt.Sprintf("%s%s_%s", PortPrefix, taskName, p.Label)
t.TaskEnv[key] = strconv.Itoa(p.Value)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion client/driver/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_META_foo=baz",
"NOMAD_ADDR_web_main=192.168.0.100:5000",
"NOMAD_ADDR_web_http=192.168.0.100:2000",
"NOMAD_PORT_web_main=5000",
"NOMAD_PORT_web_http=2000",
"NOMAD_IP_web_main=192.168.0.100",
"NOMAD_IP_web_http=192.168.0.100",
"NOMAD_TASK_NAME=taskA",
}
allocID := fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID)
exp = append(exp, allocID)
sort.Strings(act)
sort.Strings(exp)
if !reflect.DeepEqual(act, exp) {
t.Fatalf("env.List() returned %v;\n want %v", act, exp)
t.Fatalf("env.List() returned %v;\n want:\n%v", strings.Join(act, "\n"), strings.Join(exp, "\n"))
}
}

Expand Down
10 changes: 9 additions & 1 deletion website/source/docs/runtime/environment.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ environment variables.
<td>The IP:Port pair of the port with the given label</td>
</tr>
<tr>
<td>`NOMAD_ADDR_<task>_<label`></td>
<td>`NOMAD_ADDR_<task>_<label>`</td>
<td>The allocated address, given as IP:Port for the given label of other tasks in the same group</td>
</tr>
<tr>
<td>`NOMAD_PORT_<task>_<label>`</td>
<td>The allocated port for the given label of other tasks in the same group</td>
</tr>
<tr>
<td>`NOMAD_IP_<task>_<label>`</td>
<td>The allocated IP address for the given label of other tasks in the same group</td>
</tr>
<tr>
<td>`NOMAD_HOST_PORT_<label>`</td>
<td>The host port for the given label if the port is port mapped</td>
Expand Down