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

Backport of server: Fix panic when validating non-service reschedule block. into release/1.7.x #19656

Merged
merged 1 commit into from
Jan 8, 2024
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
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