diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 55d2af7073d..670503d3699 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1080,9 +1080,9 @@ func (j *Job) Validate() error { taskGroups[tg.Name] = idx } - if j.Type == "system" && tg.Count != 1 { + if j.Type == "system" && tg.Count > 1 { mErr.Errors = append(mErr.Errors, - fmt.Errorf("Job task group %d has count %d. Only count of 1 is supported with system scheduler", + fmt.Errorf("Job task group %d has count %d. Count cannot exceed 1 with system scheduler", idx+1, tg.Count)) } } @@ -1096,7 +1096,7 @@ func (j *Job) Validate() error { } // Validate periodic is only used with batch jobs. - if j.IsPeriodic() { + if j.IsPeriodic() && j.Periodic.Enabled { if j.Type != JobTypeBatch { mErr.Errors = append(mErr.Errors, fmt.Errorf("Periodic can only be used with %q scheduler", JobTypeBatch)) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 08547f44b77..26c5302c2c8 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -117,6 +117,7 @@ func testJob() *Job { Name: "web", Count: 10, RestartPolicy: &RestartPolicy{ + Mode: RestartPolicyModeFail, Attempts: 3, Interval: 10 * time.Minute, Delay: 1 * time.Minute, @@ -145,6 +146,7 @@ func testJob() *Job { Resources: &Resources{ CPU: 500, MemoryMB: 256, + DiskMB: 20, Networks: []*NetworkResource{ &NetworkResource{ MBits: 50, @@ -152,6 +154,10 @@ func testJob() *Job { }, }, }, + LogConfig: &LogConfig{ + MaxFiles: 10, + MaxFileSizeMB: 1, + }, }, }, Meta: map[string]string{ @@ -194,6 +200,27 @@ func TestJob_IsPeriodic(t *testing.T) { } } +func TestJob_SystemJob_Validate(t *testing.T) { + j := testJob() + j.Type = JobTypeSystem + j.InitFields() + + err := j.Validate() + if err == nil || !strings.Contains(err.Error(), "exceed") { + t.Fatalf("expect error due to count") + } + + j.TaskGroups[0].Count = 0 + if err := j.Validate(); err != nil { + t.Fatalf("unexpected err: %v", err) + } + + j.TaskGroups[0].Count = 1 + if err := j.Validate(); err != nil { + t.Fatalf("unexpected err: %v", err) + } +} + func TestTaskGroup_Validate(t *testing.T) { tg := &TaskGroup{ Count: -1,