Adopted pattern from LogConfig to handle panic when no resource stanza at all

In testing realized that Resources night not be present at all.  Testing this case caused panic. Added in a means to collect clean defaults in that case.
This commit is contained in:
Charlie Voiselle
2017-11-09 10:57:57 -05:00
parent 1cb52865bc
commit 20ea6b25dc

View File

@@ -186,7 +186,7 @@ func (s *Service) Canonicalize(t *Task, tg *TaskGroup, job *Job) {
s.CheckRestart.Canonicalize()
// Canonicalize CheckRestart on Checks and merge Service.CheckRestart
// Canonicallize CheckRestart on Checks and merge Service.CheckRestart
// into each check.
for _, c := range s.Checks {
c.CheckRestart.Canonicalize()
@@ -373,8 +373,13 @@ type Task struct {
}
func (t *Task) Canonicalize(tg *TaskGroup, job *Job) {
min := MinResources()
t.Resources.Canonicalize()
if t.Resources == nil {
var r Resources
r.Canonicalize()
t.Resources = &r
} else {
t.Resources.Canonicalize()
}
if t.KillTimeout == nil {
t.KillTimeout = helper.TimeToPtr(5 * time.Second)