jobspec: job-level constraints

This commit is contained in:
Mitchell Hashimoto
2015-09-14 17:48:11 -07:00
parent a8fd4c12d9
commit 058d4bcc36
3 changed files with 21 additions and 0 deletions

View File

@@ -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, "constraint")
delete(m, "meta")
// Set the name to the object key
@@ -84,6 +85,13 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error {
return err
}
// Parse constraints
if o := obj.Get("constraint", false); o != nil {
if err := parseConstraints(&result.Constraints, o); err != nil {
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 {

View File

@@ -27,6 +27,14 @@ func TestParse(t *testing.T) {
"foo": "bar",
},
Constraints: []*structs.Constraint{
&structs.Constraint{
LTarget: "kernel.os",
RTarget: "windows",
Operand: "=",
},
},
TaskGroups: []*structs.TaskGroup{
&structs.TaskGroup{
Name: "outside",

View File

@@ -9,6 +9,11 @@ job "binstore-storagelocker" {
foo = "bar"
}
constraint {
attribute = "kernel.os"
value = "windows"
}
task "outside" {
driver = "java"
config {