From d145b395e8f36712b5b62209010b7f876959d6ca Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 10 Mar 2020 14:55:16 -0700 Subject: [PATCH] jobspec: fixup vault_grace deprecation Followup to #7170 - Moved canonicalization of VaultGrace back into `api/` package. - Fixed tests. - Made docs styling consistent. --- api/jobs_test.go | 2 ++ api/tasks.go | 5 +++++ jobspec/parse_task.go | 1 - jobspec/parse_test.go | 1 + nomad/structs/diff_test.go | 12 ++++++++++ nomad/structs/structs.go | 22 +++++++++---------- nomad/structs/structs_test.go | 20 +++++++++++++++++ .../pages/guides/upgrade/upgrade-specific.mdx | 12 +++++----- 8 files changed, 58 insertions(+), 17 deletions(-) diff --git a/api/jobs_test.go b/api/jobs_test.go index d612abf05ed..160a8a1216e 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -531,6 +531,7 @@ func TestJobs_Canonicalize(t *testing.T) { LeftDelim: stringToPtr("{{"), RightDelim: stringToPtr("}}"), Envvars: boolToPtr(false), + VaultGrace: timeToPtr(0), }, { SourcePath: stringToPtr(""), @@ -543,6 +544,7 @@ func TestJobs_Canonicalize(t *testing.T) { LeftDelim: stringToPtr("{{"), RightDelim: stringToPtr("}}"), Envvars: boolToPtr(true), + VaultGrace: timeToPtr(0), }, }, }, diff --git a/api/tasks.go b/api/tasks.go index ecb2c4e3ad3..bad4c244252 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -750,6 +750,11 @@ func (tmpl *Template) Canonicalize() { if tmpl.Envvars == nil { tmpl.Envvars = boolToPtr(false) } + + //COMPAT(0.12) VaultGrace is deprecated and unused as of Vault 0.5 + if tmpl.VaultGrace == nil { + tmpl.VaultGrace = timeToPtr(0) + } } type Vault struct { diff --git a/jobspec/parse_task.go b/jobspec/parse_task.go index b25852e2bed..997d3bfa77b 100644 --- a/jobspec/parse_task.go +++ b/jobspec/parse_task.go @@ -374,7 +374,6 @@ func parseTemplates(result *[]*api.Template, list *ast.ObjectList) error { ChangeMode: helper.StringToPtr("restart"), Splay: helper.TimeToPtr(5 * time.Second), Perms: helper.StringToPtr("0644"), - VaultGrace: helper.TimeToPtr(0), } dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 88909bbf9e1..08072e3e9c6 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -320,6 +320,7 @@ func TestParse(t *testing.T) { Splay: helper.TimeToPtr(10 * time.Second), Perms: helper.StringToPtr("0644"), Envvars: helper.BoolToPtr(true), + VaultGrace: helper.TimeToPtr(33 * time.Second), }, { SourcePath: helper.StringToPtr("bar"), diff --git a/nomad/structs/diff_test.go b/nomad/structs/diff_test.go index e39dd077de9..708e72ead82 100644 --- a/nomad/structs/diff_test.go +++ b/nomad/structs/diff_test.go @@ -5756,6 +5756,12 @@ func TestTaskDiff(t *testing.T) { Old: "", New: "3", }, + { + Type: DiffTypeAdded, + Name: "VaultGrace", + Old: "", + New: "0", + }, }, }, { @@ -5810,6 +5816,12 @@ func TestTaskDiff(t *testing.T) { Old: "2", New: "", }, + { + Type: DiffTypeDeleted, + Name: "VaultGrace", + Old: "0", + New: "", + }, }, }, }, diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 1d9b7c2f7af..49d81fb345d 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -5839,17 +5839,6 @@ func (t *Task) Warnings() error { return mErr.ErrorOrNil() } -func (t *Template) Warnings() error { - var mErr multierror.Error - - // Deprecation notice for vault_grace - if t.VaultGrace > 0 { - mErr.Errors = append(mErr.Errors, fmt.Errorf("VaultGrace has been deprecated as of Nomad 0.11 and ignored since Vault 0.5. Please remove VaultGrace / vault_grace from template stanza.")) - } - - return mErr.ErrorOrNil() -} - // TaskKind identifies the special kinds of tasks using the following format: // '(:)`. The TaskKind can optionally include an identifier that // is opaque to the Task. This identifier can be used to relate the task to some @@ -6060,6 +6049,17 @@ func (t *Template) Validate() error { return mErr.ErrorOrNil() } +func (t *Template) Warnings() error { + var mErr multierror.Error + + // Deprecation notice for vault_grace + if t.VaultGrace != 0 { + mErr.Errors = append(mErr.Errors, fmt.Errorf("VaultGrace has been deprecated as of Nomad 0.11 and ignored since Vault 0.5. Please remove VaultGrace / vault_grace from template stanza.")) + } + + return mErr.ErrorOrNil() +} + // Set of possible states for a task. const ( TaskStatePending = "pending" // The task is waiting to be run. diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index ed010f3a753..a55b4ee96ee 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -163,6 +163,26 @@ func TestJob_Warnings(t *testing.T) { }, }, }, + { + Name: "Template.VaultGrace Deprecated", + Expected: []string{"VaultGrace has been deprecated as of Nomad 0.11 and ignored since Vault 0.5. Please remove VaultGrace / vault_grace from template stanza."}, + Job: &Job{ + Type: JobTypeService, + TaskGroups: []*TaskGroup{ + { + Tasks: []*Task{ + { + Templates: []*Template{ + { + VaultGrace: 1, + }, + }, + }, + }, + }, + }, + }, + }, } for _, c := range cases { diff --git a/website/pages/guides/upgrade/upgrade-specific.mdx b/website/pages/guides/upgrade/upgrade-specific.mdx index b24b5ea5cc5..7a2533a211a 100644 --- a/website/pages/guides/upgrade/upgrade-specific.mdx +++ b/website/pages/guides/upgrade/upgrade-specific.mdx @@ -19,11 +19,12 @@ standard upgrade flow. ### client.template: `vault_grace` deprecation -Nomad 0.11.0 includes an update to [consul-template](https://github.com/hashicorp/consul-template) v0.24.1. -This library deprecates the `vault_grace` option for templating included in nomad. -The feature has been ignored since vault 0.5 and as long as you are running -a more recent version of vault, you can safely remove vault_grace from your -nomad jobs. +Nomad 0.11.0 updates +[consul-template](https://github.com/hashicorp/consul-template) to v0.24.1. +This library deprecates the [`vault_grace`][vault_grace] option for templating +included in Nomad. The feature has been ignored since Vault 0.5 and as long as +you are running a more recent version of Vault, you can safely remove +`vault_grace` from your Nomad jobs. ## Nomad 0.10.4 @@ -470,6 +471,7 @@ deleted and then Nomad 0.3.0 can be launched. [preemption-api]: /api/operator#update-scheduler-configuration [task-config]: /docs/job-specification/task#config [validate]: /docs/commands/job/validate +[vault_grace]: /docs/job-specification/template [update]: /docs/job-specification/update [tls-guide]: /guides/security/securing-nomad [tls-vault-guide]: /guides/security/vault-pki-integration