mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 11:25:41 +03:00
Distinct Property supports arbitrary limit
This PR enhances the distinct_property constraint such that a limit can
be specified in the RTarget/value parameter. This allows constraints
such as:
```
constraint {
distinct_property = "${meta.rack}"
value = "2"
}
```
This restricts any given rack from running more than 2 allocations from
the task group.
Fixes https://github.com/hashicorp/nomad/issues/1146
This commit is contained in:
@@ -537,7 +537,9 @@ The `Constraint` object supports the following keys:
|
||||
omitted.
|
||||
|
||||
- `distinct_property` - If set, the scheduler selects nodes that have a
|
||||
distinct value of the specified property for each allocation. This can
|
||||
distinct value of the specified property. The `RTarget` specifies how
|
||||
many allocations are allowed to share the value of a property. The
|
||||
`RTarget` must be 1 or greater and if omitted, defaults to 1. This can
|
||||
be specified as a job constraint which applies the constraint to all
|
||||
task groups in the job, or as a task group constraint which scopes the
|
||||
effect to just that group. The constraint may not be specified at the
|
||||
|
||||
@@ -75,6 +75,8 @@ all groups (and tasks) in the job.
|
||||
>=
|
||||
<
|
||||
<=
|
||||
distinct_hosts
|
||||
distinct_property
|
||||
regexp
|
||||
set_contains
|
||||
version
|
||||
@@ -124,16 +126,18 @@ constraint {
|
||||
```
|
||||
|
||||
- `"distinct_property"` - Instructs the scheduler to select nodes that have a
|
||||
distinct value of the specified property for each allocation. When specified
|
||||
as a job constraint, it applies to all groups in the job. When specified as a
|
||||
group constraint, the effect is constrained to that group. This constraint can
|
||||
not be specified at the task level. Note that the `value` parameter should be
|
||||
omitted when using this constraint.
|
||||
distinct value of the specified property. The `value` parameter specifies how
|
||||
many allocations are allowed to share the value of a property. The `value`
|
||||
must be 1 or greater and if omitted, defaults to 1. When specified as a job
|
||||
constraint, it applies to all groups in the job. When specified as a group
|
||||
constraint, the effect is constrained to that group. This constraint can not
|
||||
be specified at the task level.
|
||||
|
||||
```hcl
|
||||
constraint {
|
||||
operator = "distinct_property"
|
||||
attribute = "${meta.rack}"
|
||||
value = "3"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -142,7 +146,8 @@ constraint {
|
||||
|
||||
```hcl
|
||||
constraint {
|
||||
distinct_property = "${meta.rack}"
|
||||
distinct_property = "${meta.rack}"
|
||||
value = "3"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -209,13 +214,14 @@ constraint {
|
||||
A potential use case of the `distinct_property` constraint is to spread a
|
||||
service with `count > 1` across racks to minimize correlated failure. Nodes can
|
||||
be annotated with which rack they are on using [client
|
||||
metadata][client-metadata] with values
|
||||
such as "rack-12-1", "rack-12-2", etc. The following constraint would then
|
||||
assure no two instances of the task group existed on the same rack.
|
||||
metadata][client-metadata] with values such as "rack-12-1", "rack-12-2", etc.
|
||||
The following constraint would assure that an individual rack is not running
|
||||
more than 2 instances of the task group.
|
||||
|
||||
```hcl
|
||||
constraint {
|
||||
distinct_property = "${meta.rack}"
|
||||
value = "2"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user