mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
jobspec: adding sugar for regexp constraint
This commit is contained in:
@@ -249,6 +249,13 @@ func parseConstraints(result *[]*structs.Constraint, obj *hclobj.Object) error {
|
||||
m["RTarget"] = constraint
|
||||
}
|
||||
|
||||
// If "regexp" is provided, set the operand
|
||||
// to "regexp" and the value to the "RTarget"
|
||||
if constraint, ok := m["regexp"]; ok {
|
||||
m["Operand"] = "regexp"
|
||||
m["RTarget"] = constraint
|
||||
}
|
||||
|
||||
// Build the constraint
|
||||
var c structs.Constraint
|
||||
if err := mapstructure.WeakDecode(m, &c); err != nil {
|
||||
|
||||
@@ -172,6 +172,26 @@ func TestParse(t *testing.T) {
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"regexp-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: "[0-9.]+",
|
||||
Operand: "regexp",
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"specify-job.hcl",
|
||||
&structs.Job{
|
||||
|
||||
6
jobspec/test-fixtures/regexp-constraint.hcl
Normal file
6
jobspec/test-fixtures/regexp-constraint.hcl
Normal file
@@ -0,0 +1,6 @@
|
||||
job "foo" {
|
||||
constraint {
|
||||
attribute = "$attr.kernel.version"
|
||||
regexp = "[0-9.]+"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user