diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d004891fbe..66517d5766e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 04360d49b812..03ca374429b3 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -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}", diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 9182cc872754..92067040ad9a 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -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{ @@ -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")