From 0de76ddd76f0dfcfedc464d91b944e12bc00e2fc Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 26 Oct 2016 10:36:41 -0700 Subject: [PATCH 1/2] Allow omitting resource block entirely --- nomad/structs/structs.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index e0558e0861be..bbd7cac6b179 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2103,7 +2103,9 @@ func (t *Task) Canonicalize(job *Job, tg *TaskGroup) { service.Canonicalize(job.Name, tg.Name, t.Name) } - if t.Resources != nil { + if t.Resources == nil { + t.Resources = DefaultResources() + } else { t.Resources.Canonicalize() } @@ -2155,12 +2157,12 @@ func (t *Task) Validate(ephemeralDisk *EphemeralDisk) error { // Validate the resources. if t.Resources == nil { mErr.Errors = append(mErr.Errors, errors.New("Missing task resources")) - } else if err := t.Resources.MeetsMinResources(); err != nil { - mErr.Errors = append(mErr.Errors, err) - } + } else { + if err := t.Resources.MeetsMinResources(); err != nil { + mErr.Errors = append(mErr.Errors, err) + } - // Ensure the task isn't asking for disk resources - if t.Resources != nil { + // Ensure the task isn't asking for disk resources if t.Resources.DiskMB > 0 { mErr.Errors = append(mErr.Errors, errors.New("Task can't ask for disk resources, they have to be specified at the task group level.")) } From ea963ab55096e6246d14c8c8d19d4c67f26ae672 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 26 Oct 2016 13:21:09 -0700 Subject: [PATCH 2/2] Document missing task resources handling --- CHANGELOG.md | 1 + nomad/structs/structs.go | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ff251c6d6d..b13a9fa775ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ BUG FIXES: the client [GH-1641] * discovery/jobspec: Validate service name after interpolation [GH-1852] * driver/docker: Fix `local/` directory mount into container [GH-1830] + * jobspec: Tasks without a resource block no longer fail to validate [GH-1864] ## 0.4.1 (August 18, 2016) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index bbd7cac6b179..eab9d0c9f68d 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2103,6 +2103,7 @@ func (t *Task) Canonicalize(job *Job, tg *TaskGroup) { service.Canonicalize(job.Name, tg.Name, t.Name) } + // If Resources are nil initialize them to defaults, otherwise canonicalize if t.Resources == nil { t.Resources = DefaultResources() } else {