diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index e7f53ab09..8f3b88272 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1875,7 +1875,9 @@ func (t *Task) Canonicalize(job *Job, tg *TaskGroup) { service.Canonicalize(job.Name, tg.Name, t.Name) } - t.Resources.Canonicalize() + if t.Resources != nil { + t.Resources.Canonicalize() + } // Set the default timeout if it is not specified. if t.KillTimeout == 0 { diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 55b911540..6a8a57545 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -88,7 +88,7 @@ func TestJob_Validate(t *testing.T) { if !strings.Contains(mErr.Errors[1].Error(), "group 3 missing name") { t.Fatalf("err: %s", err) } - if !strings.Contains(mErr.Errors[2].Error(), "Task group 1 validation failed") { + if !strings.Contains(mErr.Errors[2].Error(), "Task group web validation failed") { t.Fatalf("err: %s", err) } } @@ -258,6 +258,7 @@ func TestTaskGroup_Validate(t *testing.T) { Mode: RestartPolicyModeDelay, }, } + err = tg.Validate() mErr = err.(*multierror.Error) if !strings.Contains(mErr.Errors[0].Error(), "2 redefines 'web' from task 1") { @@ -266,7 +267,7 @@ func TestTaskGroup_Validate(t *testing.T) { if !strings.Contains(mErr.Errors[1].Error(), "Task 3 missing name") { t.Fatalf("err: %s", err) } - if !strings.Contains(mErr.Errors[2].Error(), "Task 1 validation failed") { + if !strings.Contains(mErr.Errors[2].Error(), "Task web validation failed") { t.Fatalf("err: %s", err) } }