mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
jobspec: job-level constraints
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -9,6 +9,11 @@ job "binstore-storagelocker" {
|
||||
foo = "bar"
|
||||
}
|
||||
|
||||
constraint {
|
||||
attribute = "kernel.os"
|
||||
value = "windows"
|
||||
}
|
||||
|
||||
task "outside" {
|
||||
driver = "java"
|
||||
config {
|
||||
|
||||
Reference in New Issue
Block a user