From 7079ad0c42c4223cc98643a1b863cca4e604b281 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 25 Jul 2017 10:28:50 -0700 Subject: [PATCH 1/4] Mention env templates in nomad init --- command/init.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/command/init.go b/command/init.go index b83c7cea9..b9e7ac43e 100644 --- a/command/init.go +++ b/command/init.go @@ -337,6 +337,15 @@ job "example" { # change_signal = "SIGHUP" # } + # The "template" stanza can also be used to create env vars for tasks + # that prefer those to config files. + # + # 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 From 58d5cd140d41bf5b3f728bbe2d0889ed578a2fed Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 25 Jul 2017 16:26:42 -0700 Subject: [PATCH 2/4] Mention restart --- command/init.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/command/init.go b/command/init.go index b9e7ac43e..771b54f93 100644 --- a/command/init.go +++ b/command/init.go @@ -337,8 +337,9 @@ job "example" { # change_signal = "SIGHUP" # } - # The "template" stanza can also be used to create env vars for tasks - # that prefer those to config files. + # 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\" }}" From e76d1e56ec1183e83ec3a88e99076b5540ea66c1 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 25 Jul 2017 16:34:41 -0700 Subject: [PATCH 3/4] Prevent using env templates with signals --- nomad/structs/structs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 4e220c018..0cd56096c 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3338,6 +3338,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) } From 99f97627878b12015a604ac8efbfd823bdb2069e Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 25 Jul 2017 20:27:18 -0700 Subject: [PATCH 4/4] Test for template envvar validation --- nomad/structs/structs_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 115447efc..462de13d7 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -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) {