server: Fix panic when validating non-service reschedule block. (#19652)

This commit is contained in:
James Rasell
2024-01-08 14:14:00 +00:00
committed by GitHub
parent 6bbd3b0cec
commit fbea8d1051
3 changed files with 37 additions and 1 deletions

3
.changelog/19652.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
server: Fix panic when validating non-service reschedule block
```

View File

@@ -4674,7 +4674,7 @@ func (j *Job) Validate() error {
} }
if tg.MaxClientDisconnect != nil && if tg.MaxClientDisconnect != nil &&
tg.ReschedulePolicy.Attempts > 0 && (tg.ReschedulePolicy != nil && tg.ReschedulePolicy.Attempts > 0) &&
tg.PreventRescheduleOnLost { tg.PreventRescheduleOnLost {
err := fmt.Errorf("max_client_disconnect and prevent_reschedule_on_lost cannot be enabled when rechedule.attempts > 0") err := fmt.Errorf("max_client_disconnect and prevent_reschedule_on_lost cannot be enabled when rechedule.attempts > 0")
mErr.Errors = append(mErr.Errors, err) mErr.Errors = append(mErr.Errors, err)

View File

@@ -470,6 +470,39 @@ func TestJob_ValidateNullChar(t *testing.T) {
assert.Error(job.Validate(), "null character in task name should not validate") 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) { func TestJob_Warnings(t *testing.T) {
ci.Parallel(t) ci.Parallel(t)