Skip to content

Commit

Permalink
Merge pull request #1421 from hashicorp/f-system-count-zero
Browse files Browse the repository at this point in the history
Allow count 0 on system jobs
  • Loading branch information
dadgar authored Jul 13, 2016
2 parents 4b214f3 + d3906b0 commit 47f163b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,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))
}
}
Expand All @@ -1112,7 +1112,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))
Expand Down
27 changes: 27 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -145,13 +146,18 @@ func testJob() *Job {
Resources: &Resources{
CPU: 500,
MemoryMB: 256,
DiskMB: 20,
Networks: []*NetworkResource{
&NetworkResource{
MBits: 50,
DynamicPorts: []Port{{Label: "http"}},
},
},
},
LogConfig: &LogConfig{
MaxFiles: 10,
MaxFileSizeMB: 1,
},
},
},
Meta: map[string]string{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 47f163b

Please sign in to comment.