Skip to content

Commit

Permalink
Allow specification of template delimiters
Browse files Browse the repository at this point in the history
This PR adds support for specifying the delimiters used in the template.

Fixes #2312
  • Loading branch information
dadgar committed Feb 14, 2017
1 parent d1b61e2 commit f1766fc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
2 changes: 2 additions & 0 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ type Template struct {
ChangeSignal string
Splay time.Duration
Perms string
LeftDelim *string
RightDelim *string
}

type Vault struct {
Expand Down
2 changes: 2 additions & 0 deletions client/consul_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ func parseTemplateConfigs(tmpls []*structs.Template, taskDir string,
ct.Source = &src
ct.Destination = &dest
ct.Contents = &tmpl.EmbeddedTmpl
ct.LeftDelim = &tmpl.LeftDelim
ct.RightDelim = &tmpl.RightDelim

// Set the permissions
if tmpl.Perms != "" {
Expand Down
2 changes: 2 additions & 0 deletions jobspec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ func parseTemplates(result *[]*structs.Template, list *ast.ObjectList) error {
"change_signal",
"data",
"destination",
"left_delimiter",
"perms",
"right_delimiter",
"source",
"splay",
}
Expand Down
2 changes: 2 additions & 0 deletions jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func TestParse(t *testing.T) {
ChangeSignal: "",
Splay: 5 * time.Second,
Perms: "777",
LeftDelim: "--",
RightDelim: "__",
},
},
Leader: true,
Expand Down
2 changes: 2 additions & 0 deletions jobspec/test-fixtures/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ job "binstore-storagelocker" {
source = "bar"
destination = "bar"
perms = "777"
left_delimiter = "--"
right_delimiter = "__"
}
}

Expand Down
5 changes: 5 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,11 @@ type Template struct {

// Perms is the permission the file should be written out with.
Perms string `mapstructure:"perms"`

// LeftDelim and RightDelim are optional configurations to control what
// delimiter is utilized when parsing the template.
LeftDelim string `mapstructure:"left_delimiter"`
RightDelim string `mapstructure:"right_delimiter"`
}

// DefaultTemplate returns a default template.
Expand Down
36 changes: 22 additions & 14 deletions website/source/docs/http/json-jobs.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,6 @@ README][ct].

`Template` object supports following attributes:

* `SourcePath` - Specifies the path to the template to be rendered. `SourcePath`
is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched
using an [`Artifact`](#artifact) resource. The template must exist on the
machine prior to starting the task; it is not possible to reference a template
inside of a Docker container, for example.

* `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath`
or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller
templates, but we recommend using `SourcePath` for larger templates.

* `DestPath` - Specifies the location where the resulting template should be
rendered, relative to the task directory.

- `ChangeMode` - Specifies the behavior Nomad should take if the rendered
template changes. The default value is `"restart"`. The possible values are:

Expand All @@ -685,9 +672,30 @@ README][ct].
"SIGUSR1" or "SIGINT". This option is required if the `ChangeMode` is
`signal`.

* `perms` - Specifies the rendered template's permissions. File permissions are
* `DestPath` - Specifies the location where the resulting template should be
rendered, relative to the task directory.

* `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath`
or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller
templates, but we recommend using `SourcePath` for larger templates.

* `LeftDelim` - Specifies the left delimiter to use in the template. The default
is "{{" for some templates, it may be easier to use a different delimiter that
does not conflict with the output file itself.

* `Perms` - Specifies the rendered template's permissions. File permissions are
given as octal of the unix file permissions rwxrwxrwx.

* `RightDelim` - Specifies the right delimiter to use in the template. The default
is "}}" for some templates, it may be easier to use a different delimiter that
does not conflict with the output file itself.

* `SourcePath` - Specifies the path to the template to be rendered. `SourcePath`
is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched
using an [`Artifact`](#artifact) resource. The template must exist on the
machine prior to starting the task; it is not possible to reference a template
inside of a Docker container, for example.

* `Splay` - Specifies a random amount of time to wait between 0ms and the given
splay value before invoking the change mode. Should be specified in
nanoseconds.
Expand Down
8 changes: 8 additions & 0 deletions website/source/docs/job-specification/template.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ README][ct].
- `destination` `(string: <required>)` - Specifies the location where the
resulting template should be rendered, relative to the task directory.

* `left_delimiter` `(string: "{{")` - Specifies the left delimiter to use in the
template. The default is "{{" for some templates, it may be easier to use a
different delimiter that does not conflict with the output file itself.

- `perms` `(string: "666")` - Specifies the rendered template's permissions.
File permissions are given as octal of the unix file permissions rwxrwxrwx.

* `right_delimiter` `(string: "}}")` - Specifies the right delimiter to use in the
template. The default is "}}" for some templates, it may be easier to use a
different delimiter that does not conflict with the output file itself.

- `source` `(string: "")` - Specifies the path to the template to be rendered.
One of `source` or `data` must be specified, but not both. This source can
optionally be fetched using an [`artifact`][artifact] resource. This template
Expand Down

0 comments on commit f1766fc

Please sign in to comment.