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

disconnected clients: TaskGroup validation #12418

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6213,6 +6213,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
3 changes: 3 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5258,14 +5258,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