Treat set_contains as a synonym of set_contains_all
This commit is contained in:
parent
e85a721cfb
commit
0bc030c6fb
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -97,8 +97,8 @@ job "binstore-storagelocker" {
|
|||
|
||||
affinity {
|
||||
attribute = "${meta.foo}"
|
||||
value = "bar"
|
||||
operator = "="
|
||||
value = "a,b,c"
|
||||
operator = "set_contains"
|
||||
weight = 25
|
||||
}
|
||||
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue