jobspec: adding sugar for version constraint

This commit is contained in:
Armon Dadgar 2015-10-11 15:20:58 -04:00
parent 86ca7c59a1
commit 8406bfede5
3 changed files with 33 additions and 0 deletions

View File

@ -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 {

View File

@ -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{

View File

@ -0,0 +1,6 @@
job "foo" {
constraint {
attribute = "$attr.kernel.version"
version = "~> 3.2"
}
}