Skip to content

Commit

Permalink
backport of commit fbea8d1
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell authored Jan 8, 2024
1 parent 6f0c1c8 commit ba3544c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/19652.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
server: Fix panic when validating non-service reschedule block
```
2 changes: 1 addition & 1 deletion nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4674,7 +4674,7 @@ func (j *Job) Validate() error {
}

if tg.MaxClientDisconnect != nil &&
tg.ReschedulePolicy.Attempts > 0 &&
(tg.ReschedulePolicy != nil && tg.ReschedulePolicy.Attempts > 0) &&
tg.PreventRescheduleOnLost {
err := fmt.Errorf("max_client_disconnect and prevent_reschedule_on_lost cannot be enabled when rechedule.attempts > 0")
mErr.Errors = append(mErr.Errors, err)
Expand Down
33 changes: 33 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,39 @@ func TestJob_ValidateNullChar(t *testing.T) {
assert.Error(job.Validate(), "null character in task name should not validate")
}

func TestJob_Validate_DisconnectRescheduleLost(t *testing.T) {
ci.Parallel(t)

// Craft our speciality jobspec to test this particular use-case.
testDisconnectRescheduleLostJob := &Job{
ID: "gh19644",
Name: "gh19644",
Region: "global",
Type: JobTypeSystem,
TaskGroups: []*TaskGroup{
{
Name: "cache",
MaxClientDisconnect: pointer.Of(1 * time.Hour),
PreventRescheduleOnLost: true,
Tasks: []*Task{
{
Name: "redis",
Driver: "docker",
Config: map[string]interface{}{
"image": "redis:7",
},
LogConfig: DefaultLogConfig(),
},
},
},
},
}

testDisconnectRescheduleLostJob.Canonicalize()

must.NoError(t, testDisconnectRescheduleLostJob.Validate())
}

func TestJob_Warnings(t *testing.T) {
ci.Parallel(t)

Expand Down

0 comments on commit ba3544c

Please sign in to comment.