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

Allow count 0 on system jobs #1421

Merged
merged 1 commit into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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))
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