Merge pull request #2899 from hashicorp/d-mention-env-in-init

Mention env templates in nomad init
This commit is contained in:
Michael Schurter 2017-07-26 11:17:47 -07:00 committed by GitHub
commit 7cbae6e168
3 changed files with 29 additions and 0 deletions

View File

@ -337,6 +337,16 @@ job "example" {
# change_signal = "SIGHUP"
# }
# The "template" stanza can also be used to create environment variables
# for tasks that prefer those to config files. The task will be restarted
# when data pulled from Consul or Vault changes.
#
# template {
# data = "KEY={{ key \"service/my-key\" }}"
# destination = "local/file.env"
# env = true
# }
# The "vault" stanza instructs the Nomad client to acquire a token from
# a HashiCorp Vault server. The Nomad servers must be configured and
# authorized to communicate with Vault. By default, Nomad will inject

View File

@ -3341,6 +3341,9 @@ func (t *Template) Validate() error {
if t.ChangeSignal == "" {
multierror.Append(&mErr, fmt.Errorf("Must specify signal value when change mode is signal"))
}
if t.Envvars {
multierror.Append(&mErr, fmt.Errorf("cannot use signals with env var templates"))
}
default:
multierror.Append(&mErr, TemplateChangeModeInvalidError)
}

View File

@ -1167,6 +1167,22 @@ func TestTask_Validate_Template(t *testing.T) {
if !strings.Contains(err.Error(), "same destination as") {
t.Fatalf("err: %s", err)
}
// Env templates can't use signals
task.Templates = []*Template{
{
Envvars: true,
ChangeMode: "signal",
},
}
err = task.Validate(ephemeralDisk)
if err == nil {
t.Fatalf("expected error from Template.Validate")
}
if expected := "cannot use signals"; !strings.Contains(err.Error(), expected) {
t.Errorf("expected to find %q but found %v", expected, err)
}
}
func TestTemplate_Validate(t *testing.T) {