Treat set_contains as a synonym of set_contains_all

This commit is contained in:
Preetha Appan 2018-07-18 14:36:02 -05:00
parent e85a721cfb
commit 0bc030c6fb
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
4 changed files with 14 additions and 6 deletions

View File

@ -601,6 +601,7 @@ func parseAffinities(result *[]*api.Affinity, list *ast.ObjectList) error {
"attribute",
"operator",
"regexp",
"set_contains",
"set_contains_any",
"set_contains_all",
"value",
@ -648,6 +649,12 @@ func parseAffinities(result *[]*api.Affinity, list *ast.ObjectList) error {
m["RTarget"] = affinity
}
// set_contains is a synonym of set_contains_all
if affinity, ok := m[structs.ConstraintSetContains]; ok {
m["Operand"] = structs.ConstraintSetContains
m["RTarget"] = affinity
}
// Build the affinity
var a api.Affinity
if err := mapstructure.WeakDecode(m, &a); err != nil {

View File

@ -151,8 +151,8 @@ func TestParse(t *testing.T) {
Affinities: []*api.Affinity{
{
LTarget: "${meta.foo}",
RTarget: "bar",
Operand: "=",
RTarget: "a,b,c",
Operand: "set_contains",
Weight: 25,
},
},

View File

@ -97,8 +97,8 @@ job "binstore-storagelocker" {
affinity {
attribute = "${meta.foo}"
value = "bar"
operator = "="
value = "a,b,c"
operator = "set_contains"
weight = 25
}

View File

@ -5305,7 +5305,8 @@ type Affinity struct {
func (a *Affinity) Equal(o *Affinity) bool {
return a.LTarget == o.LTarget &&
a.RTarget == o.RTarget &&
a.Operand == o.Operand
a.Operand == o.Operand &&
a.Weight == o.Weight
}
func (a *Affinity) Copy() *Affinity {
@ -5333,7 +5334,7 @@ func (a *Affinity) Validate() error {
// Perform additional validation based on operand
switch a.Operand {
case AffinitySetContainsAll, AffinitySetContainsAny:
case AffinitySetContainsAll, AffinitySetContainsAny, ConstraintSetContains:
if a.RTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Set contains operators require an RTarget"))
}