jobspec: adding sugar for version constraint
This commit is contained in:
parent
86ca7c59a1
commit
8406bfede5
|
@ -242,6 +242,13 @@ func parseConstraints(result *[]*structs.Constraint, obj *hclobj.Object) error {
|
|||
m["hard"] = true
|
||||
}
|
||||
|
||||
// If "version" is provided, set the operand
|
||||
// to "version" and the value to the "RTarget"
|
||||
if constraint, ok := m["version"]; ok {
|
||||
m["Operand"] = "version"
|
||||
m["RTarget"] = constraint
|
||||
}
|
||||
|
||||
// Build the constraint
|
||||
var c structs.Constraint
|
||||
if err := mapstructure.WeakDecode(m, &c); err != nil {
|
||||
|
|
|
@ -152,6 +152,26 @@ func TestParse(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"version-constraint.hcl",
|
||||
&structs.Job{
|
||||
ID: "foo",
|
||||
Name: "foo",
|
||||
Priority: 50,
|
||||
Region: "global",
|
||||
Type: "service",
|
||||
Constraints: []*structs.Constraint{
|
||||
&structs.Constraint{
|
||||
Hard: true,
|
||||
LTarget: "$attr.kernel.version",
|
||||
RTarget: "~> 3.2",
|
||||
Operand: "version",
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"specify-job.hcl",
|
||||
&structs.Job{
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
job "foo" {
|
||||
constraint {
|
||||
attribute = "$attr.kernel.version"
|
||||
version = "~> 3.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue