diff --git a/jobspec/parse.go b/jobspec/parse.go index b6b779c74..3a1929d13 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -306,7 +306,7 @@ func parseTasks(result *[]*structs.Task, obj *hclobj.Object) error { if o := o.Get("resources", false); o != nil { var r structs.Resources if err := parseResources(&r, o); err != nil { - return err + return fmt.Errorf("task '%s': %s", t.Name, err) } t.Resources = &r @@ -319,6 +319,10 @@ func parseTasks(result *[]*structs.Task, obj *hclobj.Object) error { } func parseResources(result *structs.Resources, obj *hclobj.Object) error { + if obj.Len() > 1 { + return fmt.Errorf("only one 'resource' block allowed per task") + } + for _, o := range obj.Elem(false) { var m map[string]interface{} if err := hcl.DecodeObject(&m, o); err != nil { @@ -332,6 +336,10 @@ func parseResources(result *structs.Resources, obj *hclobj.Object) error { // Parse the network resources if o := o.Get("network", false); o != nil { + if o.Len() > 1 { + return fmt.Errorf("only one 'network' resource allowed") + } + var r structs.NetworkResource var m map[string]interface{} if err := hcl.DecodeObject(&m, o); err != nil { diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 802fc763c..49d4f98f3 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -112,6 +112,18 @@ func TestParse(t *testing.T) { }, false, }, + + { + "multi-network.hcl", + nil, + true, + }, + + { + "multi-resource.hcl", + nil, + true, + }, } for _, tc := range cases { diff --git a/jobspec/test-fixtures/multi-network.hcl b/jobspec/test-fixtures/multi-network.hcl new file mode 100644 index 000000000..f6fe09544 --- /dev/null +++ b/jobspec/test-fixtures/multi-network.hcl @@ -0,0 +1,25 @@ +job "binstore-storagelocker" { + group "binsl" { + count = 5 + task "binstore" { + driver = "docker" + + resources { + cpu = 500 + memory = 128 + + network { + mbits = "100" + reserved_ports = [1,2,3] + dynamic_ports = 3 + } + + network { + mbits = "128" + reserved_ports = [1,2,3] + dynamic_ports = 3 + } + } + } + } +} diff --git a/jobspec/test-fixtures/multi-resource.hcl b/jobspec/test-fixtures/multi-resource.hcl new file mode 100644 index 000000000..3058ea485 --- /dev/null +++ b/jobspec/test-fixtures/multi-resource.hcl @@ -0,0 +1,18 @@ +job "binstore-storagelocker" { + group "binsl" { + count = 5 + task "binstore" { + driver = "docker" + + resources { + cpu = 500 + memory = 128 + } + + resources { + cpu = 500 + memory = 128 + } + } + } +}