Skip to content

Commit

Permalink
fix: job canonicalization should set job priority to 50, not 0. (#17314)
Browse files Browse the repository at this point in the history
Nomad API will reject jobs with priority set to 0.
  • Loading branch information
pkazmierczak committed May 30, 2023
1 parent d08fbe2 commit cd0b7be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 4 additions & 1 deletion api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const (
// on all clients.
JobTypeSysbatch = "sysbatch"

// JobDefaultPriority is the default priority if not specified.
JobDefaultPriority = 50

// PeriodicSpecCron is used for a cron spec.
PeriodicSpecCron = "cron"

Expand Down Expand Up @@ -938,7 +941,7 @@ func (j *Job) Canonicalize() {
j.Namespace = pointerOf(DefaultNamespace)
}
if j.Priority == nil {
j.Priority = pointerOf(50)
j.Priority = pointerOf(JobDefaultPriority)
}
if j.Stop == nil {
j.Stop = pointerOf(false)
Expand Down
19 changes: 10 additions & 9 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/api/internal/testutil"
"github.com/shoenig/test/must"
"github.com/shoenig/test/wait"

"github.com/hashicorp/nomad/api/internal/testutil"
)

func TestJobs_Register(t *testing.T) {
Expand Down Expand Up @@ -279,7 +280,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Namespace: pointerOf(DefaultNamespace),
Type: pointerOf("service"),
ParentID: pointerOf(""),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Namespace: pointerOf(DefaultNamespace),
Type: pointerOf("batch"),
ParentID: pointerOf(""),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -452,7 +453,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -621,7 +622,7 @@ func TestJobs_Canonicalize(t *testing.T) {
ID: pointerOf("example_template"),
Name: pointerOf("example_template"),
ParentID: pointerOf(""),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
Region: pointerOf("global"),
Type: pointerOf("service"),
AllAtOnce: pointerOf(false),
Expand Down Expand Up @@ -791,7 +792,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Name: pointerOf("bar"),
Region: pointerOf("global"),
Type: pointerOf("service"),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -882,7 +883,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -1058,7 +1059,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -1229,7 +1230,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(50),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down

0 comments on commit cd0b7be

Please sign in to comment.