Merge pull request #1421 from hashicorp/f-system-count-zero
Allow count 0 on system jobs
This commit is contained in:
commit
c28027bc9e
|
@ -1096,9 +1096,9 @@ func (j *Job) Validate() error {
|
||||||
taskGroups[tg.Name] = idx
|
taskGroups[tg.Name] = idx
|
||||||
}
|
}
|
||||||
|
|
||||||
if j.Type == "system" && tg.Count != 1 {
|
if j.Type == "system" && tg.Count > 1 {
|
||||||
mErr.Errors = append(mErr.Errors,
|
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))
|
idx+1, tg.Count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1112,7 @@ func (j *Job) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate periodic is only used with batch jobs.
|
// Validate periodic is only used with batch jobs.
|
||||||
if j.IsPeriodic() {
|
if j.IsPeriodic() && j.Periodic.Enabled {
|
||||||
if j.Type != JobTypeBatch {
|
if j.Type != JobTypeBatch {
|
||||||
mErr.Errors = append(mErr.Errors,
|
mErr.Errors = append(mErr.Errors,
|
||||||
fmt.Errorf("Periodic can only be used with %q scheduler", JobTypeBatch))
|
fmt.Errorf("Periodic can only be used with %q scheduler", JobTypeBatch))
|
||||||
|
|
|
@ -117,6 +117,7 @@ func testJob() *Job {
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Count: 10,
|
Count: 10,
|
||||||
RestartPolicy: &RestartPolicy{
|
RestartPolicy: &RestartPolicy{
|
||||||
|
Mode: RestartPolicyModeFail,
|
||||||
Attempts: 3,
|
Attempts: 3,
|
||||||
Interval: 10 * time.Minute,
|
Interval: 10 * time.Minute,
|
||||||
Delay: 1 * time.Minute,
|
Delay: 1 * time.Minute,
|
||||||
|
@ -145,6 +146,7 @@ func testJob() *Job {
|
||||||
Resources: &Resources{
|
Resources: &Resources{
|
||||||
CPU: 500,
|
CPU: 500,
|
||||||
MemoryMB: 256,
|
MemoryMB: 256,
|
||||||
|
DiskMB: 20,
|
||||||
Networks: []*NetworkResource{
|
Networks: []*NetworkResource{
|
||||||
&NetworkResource{
|
&NetworkResource{
|
||||||
MBits: 50,
|
MBits: 50,
|
||||||
|
@ -152,6 +154,10 @@ func testJob() *Job {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
LogConfig: &LogConfig{
|
||||||
|
MaxFiles: 10,
|
||||||
|
MaxFileSizeMB: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Meta: map[string]string{
|
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) {
|
func TestTaskGroup_Validate(t *testing.T) {
|
||||||
tg := &TaskGroup{
|
tg := &TaskGroup{
|
||||||
Count: -1,
|
Count: -1,
|
||||||
|
|
Loading…
Reference in a new issue