Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort signals in implicit constraint #4216

Merged
merged 2 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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