Skip to content

Commit

Permalink
Merge pull request #10702 from hashicorp/f-cc-constraints
Browse files Browse the repository at this point in the history
consul/connect: use additional constraints in scheduling connect tasks
  • Loading branch information
shoenig authored Jun 4, 2021
2 parents 9a8c68f + c90471d commit b0ac228
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMPROVEMENTS:
* cli: Added success confirmation message for `nomad volume delete` and `nomad volume deregister`. [[GH-10591](https://github.com/hashicorp/nomad/issues/10591)]
* cli: Cross-namespace `nomad job` commands will now select exact matches if the selection is unambiguous. [[GH-10648](https://github.com/hashicorp/nomad/issues/10648)]
* client/fingerprint: Consul fingerprinter probes for additional enterprise and connect related attributes [[GH-10699](https://github.com/hashicorp/nomad/pull/10699)]
* consul/connect: Only schedule connect tasks on nodes where connect is enabled in Consul [[GH-10702](https://github.com/hashicorp/nomad/pull/10702)]
* csi: Validate that `volume` blocks for CSI volumes include the required `attachment_mode` and `access_mode` fields. [[GH-10651](https://github.com/hashicorp/nomad/issues/10651)]

BUG FIXES:
Expand Down
20 changes: 20 additions & 0 deletions nomad/job_endpoint_hook_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ func connectGatewayVersionConstraint() *structs.Constraint {
}
}

func connectEnabledConstraint() *structs.Constraint {
return &structs.Constraint{
LTarget: "${attr.consul.connect}",
RTarget: "true",
Operand: "=",
}
}

func connectListenerConstraint() *structs.Constraint {
return &structs.Constraint{
LTarget: "${attr.consul.grpc}",
RTarget: "0",
Operand: ">",
}
}

// jobConnectHook implements a job Mutating and Validating admission controller
type jobConnectHook struct{}

Expand Down Expand Up @@ -414,6 +430,8 @@ func newConnectGatewayTask(prefix, service string, netHost bool) *structs.Task {
Resources: connectSidecarResources(),
Constraints: structs.Constraints{
connectGatewayVersionConstraint(),
connectEnabledConstraint(),
connectListenerConstraint(),
},
}
}
Expand All @@ -437,6 +455,8 @@ func newConnectSidecarTask(service string) *structs.Task {
},
Constraints: structs.Constraints{
connectSidecarVersionConstraint(),
connectEnabledConstraint(),
connectListenerConstraint(),
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions nomad/job_endpoint_hook_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func TestJobEndpointConnect_groupConnectHook_IngressGateway_CustomTask(t *testin
KillSignal: "SIGHUP",
Constraints: structs.Constraints{
connectGatewayVersionConstraint(),
connectEnabledConstraint(),
connectListenerConstraint(),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8234,15 +8234,15 @@ const (
ConstraintAttributeIsNotSet = "is_not_set"
)

// Constraints are used to restrict placement options.
// A Constraint is used to restrict placement options.
type Constraint struct {
LTarget string // Left-hand target
RTarget string // Right-hand target
Operand string // Constraint operand (<=, <, =, !=, >, >=), contains, near
str string // Memoized string
}

// Equal checks if two constraints are equal
// Equals checks if two constraints are equal
func (c *Constraint) Equals(o *Constraint) bool {
return c == o ||
c.LTarget == o.LTarget &&
Expand Down

0 comments on commit b0ac228

Please sign in to comment.