diff --git a/jobspec/parse.go b/jobspec/parse.go index b751c191a..7c63a4287 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -74,6 +74,7 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error { if err := hcl.DecodeObject(&m, obj); err != nil { return err } + delete(m, "meta") // Set the name to the object key result.Name = obj.Key @@ -83,6 +84,20 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error { return err } + // Parse out meta fields. These are in HCL as a list so we need + // to iterate over them and merge them. + if metaO := obj.Get("meta", false); metaO != nil { + for _, o := range metaO.Elem(false) { + var m map[string]interface{} + if err := hcl.DecodeObject(&m, o); err != nil { + return err + } + if err := mapstructure.WeakDecode(m, &result.Meta); err != nil { + return err + } + } + } + // If we have tasks outside, do those if o := obj.Get("task", false); o != nil { var tasks []*structs.Task diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 14ddf90c3..ab68c90d7 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -23,6 +23,10 @@ func TestParse(t *testing.T) { AllAtOnce: true, Datacenters: []string{"us2", "eu1"}, + Meta: map[string]string{ + "foo": "bar", + }, + TaskGroups: []*structs.TaskGroup{ &structs.TaskGroup{ Name: "outside", diff --git a/jobspec/test-fixtures/basic.hcl b/jobspec/test-fixtures/basic.hcl index 8b2b1e03e..175997182 100644 --- a/jobspec/test-fixtures/basic.hcl +++ b/jobspec/test-fixtures/basic.hcl @@ -5,6 +5,10 @@ job "binstore-storagelocker" { all_at_once = true datacenters = ["us2", "eu1"] + meta { + foo = "bar" + } + task "outside" { driver = "java" config {