Skip to content

Commit

Permalink
disconnected clients: TaskGroup validation (#12418)
Browse files Browse the repository at this point in the history
* TaskGroup: Validate that max_client_disconnect and stop_after_client_disconnect are mutually exclusive.
  • Loading branch information
DerekStrickland authored and DerekStrickland committed Apr 5, 2022
1 parent 8ac3e64 commit 6791147
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6294,6 +6294,10 @@ func (tg *TaskGroup) Validate(j *Job) error {
mErr.Errors = append(mErr.Errors, errors.New("Missing tasks for task group"))
}

if tg.MaxClientDisconnect != nil && tg.StopAfterClientDisconnect != nil {
mErr.Errors = append(mErr.Errors, errors.New("Task group cannot be configured with both max_client_disconnect and stop_after_client_disconnect"))
}

if tg.MaxClientDisconnect != nil && *tg.MaxClientDisconnect < 0 {
mErr.Errors = append(mErr.Errors, errors.New("max_client_disconnect cannot be negative"))
}
Expand Down
5 changes: 3 additions & 2 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ func testJob() *Job {
"elb_check_interval": "30s",
"elb_check_min": "3",
},
MaxClientDisconnect: helper.TimeToPtr(1 * time.Hour),
},
},
Meta: map[string]string{
Expand Down Expand Up @@ -5880,7 +5879,6 @@ func TestParameterizedJobConfig_Validate_NonBatch(t *testing.T) {

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

// Setup a system Job with stop_after_client_disconnect set, which is invalid
job := testJob()
job.Type = JobTypeSystem
Expand Down Expand Up @@ -5912,14 +5910,17 @@ func TestJobConfig_Validate_MaxClientDisconnect(t *testing.T) {
job := testJob()
timeout := -1 * time.Minute
job.TaskGroups[0].MaxClientDisconnect = &timeout
job.TaskGroups[0].StopAfterClientDisconnect = &timeout

err := job.Validate()
require.Error(t, err)
require.Contains(t, err.Error(), "max_client_disconnect cannot be negative")
require.Contains(t, err.Error(), "Task group cannot be configured with both max_client_disconnect and stop_after_client_disconnect")

// Modify the job with a valid max_client_disconnect value
timeout = 1 * time.Minute
job.TaskGroups[0].MaxClientDisconnect = &timeout
job.TaskGroups[0].StopAfterClientDisconnect = nil
err = job.Validate()
require.NoError(t, err)
}
Expand Down

0 comments on commit 6791147

Please sign in to comment.