Skip to content

Commit

Permalink
Merge pull request #4216 from hashicorp/b-signal-constraints
Browse files Browse the repository at this point in the history
Sort signals in implicit constraint
  • Loading branch information
dadgar committed Apr 26, 2018
2 parents 3a244d4 + 822693d commit 3640470
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ BUG FIXES:
* core: Fix panic when doing a node drain effecting a job that has an
allocation that was on a node that no longer exists
[[GH-4215](https://github.com/hashicorp/nomad/issues/4215)]
* core: Sort signals in implicit constraint avoiding unnecessary updates
[[GH-4216](https://github.com/hashicorp/nomad/issues/4216)]
* client: Populate access time and modify time when unarchiving tar archives
that do not specify them explicitly [[GH-4217](https://github.com/hashicorp/nomad/issues/4217)]
* driver/exec: Create process group for Windows process and send Ctrl-Break
Expand Down
1 change: 1 addition & 0 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func setImplicitConstraints(j *structs.Job) {
// getSignalConstraint builds a suitable constraint based on the required
// signals
func getSignalConstraint(signals []string) *structs.Constraint {
sort.Strings(signals)
return &structs.Constraint{
Operand: structs.ConstraintSetContains,
LTarget: "${attr.os.signals}",
Expand Down
16 changes: 13 additions & 3 deletions nomad/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3754,13 +3754,20 @@ func TestJobEndpoint_ImplicitConstraints_Signals(t *testing.T) {
// Create the register request with a job asking for a template that sends a
// signal
job := mock.Job()
signal := "SIGUSR1"
signal1 := "SIGUSR1"
signal2 := "SIGHUP"
job.TaskGroups[0].Tasks[0].Templates = []*structs.Template{
{
SourcePath: "foo",
DestPath: "bar",
ChangeMode: structs.TemplateChangeModeSignal,
ChangeSignal: signal,
ChangeSignal: signal1,
},
{
SourcePath: "foo",
DestPath: "baz",
ChangeMode: structs.TemplateChangeModeSignal,
ChangeSignal: signal2,
},
}
req := &structs.JobRegisterRequest{
Expand Down Expand Up @@ -3797,7 +3804,10 @@ func TestJobEndpoint_ImplicitConstraints_Signals(t *testing.T) {
t.Fatalf("Expected an implicit constraint")
}

sigConstraint := getSignalConstraint([]string{signal})
sigConstraint := getSignalConstraint([]string{signal1, signal2})
if !strings.HasPrefix(sigConstraint.RTarget, "SIGHUP") {
t.Fatalf("signals not sorted: %v", sigConstraint.RTarget)
}

if !constraints[0].Equal(sigConstraint) {
t.Fatalf("Expected implicit vault constraint")
Expand Down

0 comments on commit 3640470

Please sign in to comment.