diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index a8caefd2b..ba91d8fdc 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1683,6 +1683,10 @@ func (t *Task) Validate() error { mErr.Errors = append(mErr.Errors, err) } } + + if t.Resources.DiskMB <= (t.LogConfig.MaxFiles * t.LogConfig.MaxFileSizeMB) { + mErr.Errors = append(mErr.Errors, fmt.Errorf("log storage exceeds requested disk capacity")) + } return mErr.ErrorOrNil() } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 51a3603bf..b11578728 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -266,6 +266,21 @@ func TestTask_Validate(t *testing.T) { } } +func TestTask_Validate_LogConfig(t *testing.T) { + task := &Task{ + LogConfig: DefaultLogConfig(), + Resources: &Resources{ + DiskMB: 1, + }, + } + + err := task.Validate() + mErr := err.(*multierror.Error) + if !strings.Contains(mErr.Errors[3].Error(), "log storage") { + t.Fatalf("err: %s", err) + } +} + func TestConstraint_Validate(t *testing.T) { c := &Constraint{} err := c.Validate()