mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
disconnected clients: TaskGroup validation (#12418)
* TaskGroup: Validate that max_client_disconnect and stop_after_client_disconnect are mutually exclusive.
This commit is contained in:
committed by
DerekStrickland
parent
8ac3e642e6
commit
6791147254
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user