jobspec: parse job-level meta fields
This commit is contained in:
parent
9bd1c2f177
commit
8a006f2711
|
@ -74,6 +74,7 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error {
|
||||||
if err := hcl.DecodeObject(&m, obj); err != nil {
|
if err := hcl.DecodeObject(&m, obj); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
delete(m, "meta")
|
||||||
|
|
||||||
// Set the name to the object key
|
// Set the name to the object key
|
||||||
result.Name = obj.Key
|
result.Name = obj.Key
|
||||||
|
@ -83,6 +84,20 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error {
|
||||||
return err
|
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 we have tasks outside, do those
|
||||||
if o := obj.Get("task", false); o != nil {
|
if o := obj.Get("task", false); o != nil {
|
||||||
var tasks []*structs.Task
|
var tasks []*structs.Task
|
||||||
|
|
|
@ -23,6 +23,10 @@ func TestParse(t *testing.T) {
|
||||||
AllAtOnce: true,
|
AllAtOnce: true,
|
||||||
Datacenters: []string{"us2", "eu1"},
|
Datacenters: []string{"us2", "eu1"},
|
||||||
|
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
|
||||||
TaskGroups: []*structs.TaskGroup{
|
TaskGroups: []*structs.TaskGroup{
|
||||||
&structs.TaskGroup{
|
&structs.TaskGroup{
|
||||||
Name: "outside",
|
Name: "outside",
|
||||||
|
|
|
@ -5,6 +5,10 @@ job "binstore-storagelocker" {
|
||||||
all_at_once = true
|
all_at_once = true
|
||||||
datacenters = ["us2", "eu1"]
|
datacenters = ["us2", "eu1"]
|
||||||
|
|
||||||
|
meta {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
|
||||||
task "outside" {
|
task "outside" {
|
||||||
driver = "java"
|
driver = "java"
|
||||||
config {
|
config {
|
||||||
|
|
Loading…
Reference in a new issue