Skip to content

Commit

Permalink
Merge pull request #775 from hashicorp/d-interpreted-vars
Browse files Browse the repository at this point in the history
Documentation for interpreted variables
  • Loading branch information
dadgar committed Feb 11, 2016
2 parents 8571115 + 635ff6f commit c242612
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 108 deletions.
3 changes: 0 additions & 3 deletions client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const (
// The tasks limit in MHz.
CpuLimit = "NOMAD_CPU_LIMIT"

// The IP address for the task.
TaskIP = "NOMAD_IP"

// Prefix for passing both dynamic and static port allocations to
// tasks.
// E.g. $NOMAD_IP_1=127.0.0.1:1 or $NOMAD_IP_http=127.0.0.1:80
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ The following options are available for use in the job specification.
* `args` - (Optional) A list of arguments to the optional `command`. If no
`command` is present, `args` are ignored. References to environment variables
or any [intepretable Nomad
variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted
variables](/docs/jobspec/interpreted.html) will be interpreted
before launching the task. For example:

```
args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"]
args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"]
```

* `labels` - (Optional) A key/value map of labels to set to the containers on
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/exec.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ The `exec` driver supports the following configuration in the job spec:

* `args` - (Optional) A list of arguments to the optional `command`.
References to environment variables or any [intepretable Nomad
variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted
variables](/docs/jobspec/interpreted.html) will be interpreted
before launching the task. For example:

```
args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"]
args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"]
```

## Client Requirements
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/java.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ The `java` driver supports the following configuration in the job spec:

* `args` - (Optional) A list of arguments to the optional `command`.
References to environment variables or any [intepretable Nomad
variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted
variables](/docs/jobspec/interpreted.html) will be interpreted
before launching the task. For example:

```
args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"]
args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"]
```

* `jvm_options` - (Optional) A list of JVM options to be passed while invoking
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/raw_exec.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ The `raw_exec` driver supports the following configuration in the job spec:

* `args` - (Optional) A list of arguments to the optional `command`.
References to environment variables or any [intepretable Nomad
variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted
variables](/docs/jobspec/interpreted.html) will be interpreted
before launching the task. For example:

```
args = ["${nomad.ip}", "${MY_ENV}", "${meta.foo}"]
args = ["${nomad.datacenter}", "${MY_ENV}", "${meta.foo}"]
```

## Client Requirements
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/rkt.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ The `rkt` driver supports the following configuration in the job spec:

* `args` - (Optional) A list of arguments to the optional `command`.
References to environment variables or any [intepretable Nomad
variables](/docs/jobspec/index.html#interpreted_vars) will be interpreted
variables](/docs/jobspec/interpreted.html) will be interpreted
before launching the task. For example:

```
args = ["${nomad.ip}", "${MY_ENV}", ${meta.foo}"]
args = ["${nomad.datacenter}", "${MY_ENV}", ${meta.foo}"]
```

* `trust_prefix` - (Optional) The trust prefix to be passed to rkt. Must be
Expand Down
94 changes: 2 additions & 92 deletions website/source/docs/jobspec/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ The `task` object supports the following keys:
* `env` - A map of key/value representing environment variables that
will be passed along to the running process. Nomad variables are
interpreted when set in the environment variable values. See the table of
interpreted variables [here](#interpreted_vars).
interpreted variables [here](/docs/jobspec/interpreted.html).

For example the below environment map will be reinterpreted:

Expand Down Expand Up @@ -344,7 +344,7 @@ restart {
The `constraint` object supports the following keys:

* `attribute` - Specifies the attribute to examine for the
constraint. See the table of attributes [below](#interpreted_vars).
constraint. See the table of attributes [here](/docs/jobspec/interpreted.html#interpreted_node_vars).

* `operator` - Specifies the comparison operator. Defaults to equality,
and can be `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The
Expand Down Expand Up @@ -376,96 +376,6 @@ The `constraint` object supports the following keys:

Tasks within a task group are always co-scheduled.

### Interpreted Variables <a id="interpreted_vars"></a>

Certain Nomad variables are interpretable for use in constraints, task
environment variables and task arguments. Below is a table documenting the
variables that can be interpreted:

<table class="table table-bordered table-striped">
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
<tr>
<td>${node.id}</td>
<td>The client node identifier</td>
</tr>
<tr>
<td>${node.datacenter}</td>
<td>The client node datacenter</td>
</tr>
<tr>
<td>${node.name}</td>
<td>The client node name</td>
</tr>
<tr>
<td>${node.class}</td>
<td>The client node class</td>
</tr>
<tr>
<td>${attr.\<key\}></td>
<td>The attribute given by `key` on the client node.</td>
</tr>
<tr>
<td>${meta.\<key\>}</td>
<td>The metadata value given by `key` on the client node.</td>
</tr>
</table>

Below is a table documenting common node attributes:

<table class="table table-bordered table-striped">
<tr>
<th>Attribute</th>
<th>Description</th>
</tr>
<tr>
<td>arch</td>
<td>CPU architecture of the client. Examples: `amd64`, `386`</td>
</tr>
<tr>
<td>consul.datacenter</td>
<td>The Consul datacenter of the client node if Consul found</td>
</tr>
<tr>
<td>cpu.numcores</td>
<td>Number of CPU cores on the client</td>
</tr>
<tr>
<td>driver.\<key\></td>
<td>See the [task drivers](/docs/drivers/index.html) for attribute documentation</td>
</tr>
<tr>
<td>hostname</td>
<td>Hostname of the client</td>
</tr>
<tr>
<td>kernel.name</td>
<td>Kernel of the client. Examples: `linux`, `darwin`</td>
</tr>
<tr>
<td>kernel.version</td>
<td>Version of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`</td>
</tr>
<tr>
<td>platform.aws.ami-id</td>
<td>On EC2, the AMI ID of the client node</td>
</tr>
<tr>
<td>platform.aws.instance-type</td>
<td>On EC2, the instance type of the client node</td>
</tr>
<tr>
<td>os.name</td>
<td>Operating system of the client. Examples: `ubuntu`, `windows`, `darwin`</td>
</tr>
<tr>
<td>os.version</td>
<td>Version of the client OS</td>
</tr>
</table>

## JSON Syntax

Job files can also be specified in JSON. The conversion is straightforward
Expand Down
199 changes: 199 additions & 0 deletions website/source/docs/jobspec/interpreted.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
layout: "docs"
page_title: "Interpreted Variables"
sidebar_current: "docs-jobspec-interpreted"
description: |-
Learn about the Nomad's interpreted variables.
---
# Interpreted Variables

Nomad support interpreting two classes of variables, node attributes and runtime
environment variables. Node attributes are interpretable in constraints, task
environment variables and certain driver fields. Runtime environment variables
are not interpretable in constraints because they are only defined once the
scheduler has placed them on a particular node.

The syntax for interpreting variables is `${variable}`. An example and a
comprehensive list of interpretable fields can be seen below:

```
task "demo" {
driver = "docker"
# Drivers support interpreting node attributes and runtime environment
# variables
config {
image = "my-app"
# Interpret runtime variables to inject the address to bind to and the
# location to write logs to.
args = ["--bind=${NOMAD_ADDR_RPC}", "--logs=${NOMAD_ALLOC_DIR}/logs"]
port_map {
RPC = 6379
}
}
# Constraints only support node attributes as runtime environment variables
# are only defined after the task is placed on a node.
constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}
# Environment variables are interpreted and can contain both runtime and
# node attributes.
env {
"DC" = "Running on datacenter ${node.datacenter}"
"VERSION" = "Version ${NOMAD_META_VERSION}"
}
# Meta keys are also interpretable.
meta {
VERSION = "v0.3"
}
}
```

## Node Variables <a id="interpreted_node_vars"></a>

Below is a full listing of node attributes that are interpretable. These
attributes are Interpreted by __both__ constraints and within the task and
driver.

<table class="table table-bordered table-striped">
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
<tr>
<td>${node.unique.id}</td>
<td>The client node identifier</td>
</tr>
<tr>
<td>${node.datacenter}</td>
<td>The client node datacenter</td>
</tr>
<tr>
<td>${node.unique.name}</td>
<td>The client node name</td>
</tr>
<tr>
<td>${node.class}</td>
<td>The client node class</td>
</tr>
<tr>
<td>${attr.\<key\}></td>
<td>The attribute given by `key` on the client node.</td>
</tr>
<tr>
<td>${meta.\<key\>}</td>
<td>The metadata value given by `key` on the client node.</td>
</tr>
</table>

Below is a table documenting common node attributes:

<table class="table table-bordered table-striped">
<tr>
<th>Attribute</th>
<th>Description</th>
</tr>
<tr>
<td>arch</td>
<td>CPU architecture of the client. Examples: `amd64`, `386`</td>
</tr>
<tr>
<td>consul.datacenter</td>
<td>The Consul datacenter of the client node if Consul found</td>
</tr>
<tr>
<td>cpu.numcores</td>
<td>Number of CPU cores on the client</td>
</tr>
<tr>
<td>driver.\<key\></td>
<td>See the [task drivers](/docs/drivers/index.html) for attribute documentation</td>
</tr>
<tr>
<td>hostname</td>
<td>Hostname of the client</td>
</tr>
<tr>
<td>kernel.name</td>
<td>Kernel of the client. Examples: `linux`, `darwin`</td>
</tr>
<tr>
<td>kernel.version</td>
<td>Version of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`</td>
</tr>
<tr>
<td>platform.aws.ami-id</td>
<td>On EC2, the AMI ID of the client node</td>
</tr>
<tr>
<td>platform.aws.instance-type</td>
<td>On EC2, the instance type of the client node</td>
</tr>
<tr>
<td>os.name</td>
<td>Operating system of the client. Examples: `ubuntu`, `windows`, `darwin`</td>
</tr>
<tr>
<td>os.version</td>
<td>Version of the client OS</td>
</tr>
</table>

## Environment Variables <a id="interpreted_env_vars"></a>

The following are runtime environment variables that describe the environment
the task is running in. These are only defined once the task has been placed on
a particular node and as such can not be used in constraints.

<table class="table table-bordered table-striped">
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
<tr>
<td>${NOMAD_ALLOC_DIR}</td>
<td>The path to the shared `alloc/` directory. See
[here](/docs/jobspec/environment.html#task_dir) for more
information.</td>
</tr>
<tr>
<td>${NOMAD_TASK_DIR}</td>
<td>The path to the task `local/` directory. See
[here](/docs/jobspec/environment.html#task_dir) for more
information.</td>
</tr>
<tr>
<td>${NOMAD_MEMORY_LIMIT}</td>
<td>The memory limit in MBits for the task</td>
</tr>
<tr>
<td>${NOMAD_CPU_LIMIT}</td>
<td>The CPU limit in MHz for the task</td>
</tr>
<tr>
<td>${NOMAD_ADDR_"label"}></td>
<td>The `ip:port` pair for the given port `label`. See
[here](/docs/jobspec/networking.html) for more information.</td>
</tr>
<tr>
<td>${NOMAD_HOST_PORT_"label"}</td>
<td>The port on the host if port forwarding is being used for the port
`label`. See [here](/docs/jobspec/networking.html#mapped_ports) for more
information.</td>
</tr>
<tr>
<td>${NOMAD_META_"key"}</td>
<td>The metadata value given by `key` on the task's metadata</td>
</tr>
<tr>
<td>${"env_key"}</td>
<td>Interpret an environment variable with key `env_key` set on the task.</td>
</tr>
</table>

Loading

0 comments on commit c242612

Please sign in to comment.