mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
server: Fix panic when validating non-service reschedule block. (#19652)
This commit is contained in:
3
.changelog/19652.txt
Normal file
3
.changelog/19652.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
server: Fix panic when validating non-service reschedule block
|
||||||
|
```
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user