copied consts used by jobspec parsing from structs into api package, to avoid referencing structs package in jobspec (#5663)
This commit is contained in:
parent
f56342121b
commit
3f02119642
|
@ -1,5 +1,17 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
|
const (
|
||||||
|
ConstraintDistinctProperty = "distinct_property"
|
||||||
|
ConstraintDistinctHosts = "distinct_hosts"
|
||||||
|
ConstraintRegex = "regexp"
|
||||||
|
ConstraintVersion = "version"
|
||||||
|
ConstraintSetContains = "set_contains"
|
||||||
|
ConstraintSetContainsAll = "set_contains_all"
|
||||||
|
ConstraintSetContainsAny = "set_contains_any"
|
||||||
|
ConstraintAttributeIsSet = "is_set"
|
||||||
|
ConstraintAttributeIsNotSet = "is_not_set"
|
||||||
|
)
|
||||||
|
|
||||||
// Constraint is used to serialize a job placement constraint.
|
// Constraint is used to serialize a job placement constraint.
|
||||||
type Constraint struct {
|
type Constraint struct {
|
||||||
LTarget string
|
LTarget string
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/hashicorp/hcl/hcl/ast"
|
"github.com/hashicorp/hcl/hcl/ast"
|
||||||
"github.com/hashicorp/nomad/api"
|
"github.com/hashicorp/nomad/api"
|
||||||
"github.com/hashicorp/nomad/helper"
|
"github.com/hashicorp/nomad/helper"
|
||||||
"github.com/hashicorp/nomad/nomad/structs"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -559,26 +558,26 @@ func parseConstraints(result *[]*api.Constraint, list *ast.ObjectList) error {
|
||||||
|
|
||||||
// If "version" is provided, set the operand
|
// If "version" is provided, set the operand
|
||||||
// to "version" and the value to the "RTarget"
|
// to "version" and the value to the "RTarget"
|
||||||
if constraint, ok := m[structs.ConstraintVersion]; ok {
|
if constraint, ok := m[api.ConstraintVersion]; ok {
|
||||||
m["Operand"] = structs.ConstraintVersion
|
m["Operand"] = api.ConstraintVersion
|
||||||
m["RTarget"] = constraint
|
m["RTarget"] = constraint
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "regexp" is provided, set the operand
|
// If "regexp" is provided, set the operand
|
||||||
// to "regexp" and the value to the "RTarget"
|
// to "regexp" and the value to the "RTarget"
|
||||||
if constraint, ok := m[structs.ConstraintRegex]; ok {
|
if constraint, ok := m[api.ConstraintRegex]; ok {
|
||||||
m["Operand"] = structs.ConstraintRegex
|
m["Operand"] = api.ConstraintRegex
|
||||||
m["RTarget"] = constraint
|
m["RTarget"] = constraint
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "set_contains" is provided, set the operand
|
// If "set_contains" is provided, set the operand
|
||||||
// to "set_contains" and the value to the "RTarget"
|
// to "set_contains" and the value to the "RTarget"
|
||||||
if constraint, ok := m[structs.ConstraintSetContains]; ok {
|
if constraint, ok := m[api.ConstraintSetContains]; ok {
|
||||||
m["Operand"] = structs.ConstraintSetContains
|
m["Operand"] = api.ConstraintSetContains
|
||||||
m["RTarget"] = constraint
|
m["RTarget"] = constraint
|
||||||
}
|
}
|
||||||
|
|
||||||
if value, ok := m[structs.ConstraintDistinctHosts]; ok {
|
if value, ok := m[api.ConstraintDistinctHosts]; ok {
|
||||||
enabled, err := parseBool(value)
|
enabled, err := parseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("distinct_hosts should be set to true or false; %v", err)
|
return fmt.Errorf("distinct_hosts should be set to true or false; %v", err)
|
||||||
|
@ -589,11 +588,11 @@ func parseConstraints(result *[]*api.Constraint, list *ast.ObjectList) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m["Operand"] = structs.ConstraintDistinctHosts
|
m["Operand"] = api.ConstraintDistinctHosts
|
||||||
}
|
}
|
||||||
|
|
||||||
if property, ok := m[structs.ConstraintDistinctProperty]; ok {
|
if property, ok := m[api.ConstraintDistinctProperty]; ok {
|
||||||
m["Operand"] = structs.ConstraintDistinctProperty
|
m["Operand"] = api.ConstraintDistinctProperty
|
||||||
m["LTarget"] = property
|
m["LTarget"] = property
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,35 +640,35 @@ func parseAffinities(result *[]*api.Affinity, list *ast.ObjectList) error {
|
||||||
|
|
||||||
// If "version" is provided, set the operand
|
// If "version" is provided, set the operand
|
||||||
// to "version" and the value to the "RTarget"
|
// to "version" and the value to the "RTarget"
|
||||||
if affinity, ok := m[structs.ConstraintVersion]; ok {
|
if affinity, ok := m[api.ConstraintVersion]; ok {
|
||||||
m["Operand"] = structs.ConstraintVersion
|
m["Operand"] = api.ConstraintVersion
|
||||||
m["RTarget"] = affinity
|
m["RTarget"] = affinity
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "regexp" is provided, set the operand
|
// If "regexp" is provided, set the operand
|
||||||
// to "regexp" and the value to the "RTarget"
|
// to "regexp" and the value to the "RTarget"
|
||||||
if affinity, ok := m[structs.ConstraintRegex]; ok {
|
if affinity, ok := m[api.ConstraintRegex]; ok {
|
||||||
m["Operand"] = structs.ConstraintRegex
|
m["Operand"] = api.ConstraintRegex
|
||||||
m["RTarget"] = affinity
|
m["RTarget"] = affinity
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "set_contains_any" is provided, set the operand
|
// If "set_contains_any" is provided, set the operand
|
||||||
// to "set_contains_any" and the value to the "RTarget"
|
// to "set_contains_any" and the value to the "RTarget"
|
||||||
if affinity, ok := m[structs.ConstraintSetContainsAny]; ok {
|
if affinity, ok := m[api.ConstraintSetContainsAny]; ok {
|
||||||
m["Operand"] = structs.ConstraintSetContainsAny
|
m["Operand"] = api.ConstraintSetContainsAny
|
||||||
m["RTarget"] = affinity
|
m["RTarget"] = affinity
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "set_contains_all" is provided, set the operand
|
// If "set_contains_all" is provided, set the operand
|
||||||
// to "set_contains_all" and the value to the "RTarget"
|
// to "set_contains_all" and the value to the "RTarget"
|
||||||
if affinity, ok := m[structs.ConstraintSetContainsAll]; ok {
|
if affinity, ok := m[api.ConstraintSetContainsAll]; ok {
|
||||||
m["Operand"] = structs.ConstraintSetContainsAll
|
m["Operand"] = api.ConstraintSetContainsAll
|
||||||
m["RTarget"] = affinity
|
m["RTarget"] = affinity
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_contains is a synonym of set_contains_all
|
// set_contains is a synonym of set_contains_all
|
||||||
if affinity, ok := m[structs.ConstraintSetContains]; ok {
|
if affinity, ok := m[api.ConstraintSetContains]; ok {
|
||||||
m["Operand"] = structs.ConstraintSetContains
|
m["Operand"] = api.ConstraintSetContains
|
||||||
m["RTarget"] = affinity
|
m["RTarget"] = affinity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,7 +1690,7 @@ func parsePeriodic(result **api.PeriodicConfig, list *ast.ObjectList) error {
|
||||||
|
|
||||||
// If "cron" is provided, set the type to "cron" and store the spec.
|
// If "cron" is provided, set the type to "cron" and store the spec.
|
||||||
if cron, ok := m["cron"]; ok {
|
if cron, ok := m["cron"]; ok {
|
||||||
m["SpecType"] = structs.PeriodicSpecCron
|
m["SpecType"] = api.PeriodicSpecCron
|
||||||
m["Spec"] = cron
|
m["Spec"] = cron
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue