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 authored May 30, 2023
1 parent 087ac3a commit 91a434f
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 @@ -29,6 +29,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 @@ -1003,7 +1006,7 @@ func (j *Job) Canonicalize() {
j.Namespace = pointerOf(DefaultNamespace)
}
if j.Priority == nil {
j.Priority = pointerOf(0)
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 @@ -9,9 +9,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 @@ -282,7 +283,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Namespace: pointerOf(DefaultNamespace),
Type: pointerOf("service"),
ParentID: pointerOf(""),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -377,7 +378,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Namespace: pointerOf(DefaultNamespace),
Type: pointerOf("batch"),
ParentID: pointerOf(""),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -455,7 +456,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -624,7 +625,7 @@ func TestJobs_Canonicalize(t *testing.T) {
ID: pointerOf("example_template"),
Name: pointerOf("example_template"),
ParentID: pointerOf(""),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
Region: pointerOf("global"),
Type: pointerOf("service"),
AllAtOnce: pointerOf(false),
Expand Down Expand Up @@ -794,7 +795,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Name: pointerOf("bar"),
Region: pointerOf("global"),
Type: pointerOf("service"),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -885,7 +886,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -1061,7 +1062,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down Expand Up @@ -1232,7 +1233,7 @@ func TestJobs_Canonicalize(t *testing.T) {
Region: pointerOf("global"),
Type: pointerOf("service"),
ParentID: pointerOf("lol"),
Priority: pointerOf(0),
Priority: pointerOf(JobDefaultPriority),
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
Expand Down

0 comments on commit 91a434f

Please sign in to comment.