diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 154e2b92c..edbdf3489 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2904,6 +2904,7 @@ func (r *ReschedulePolicy) Validate() error { if r.Unlimited { multierror.Append(&mErr, fmt.Errorf("Reschedule Policy with Attempts = %v, Interval = %v, "+ "and Unlimited = %v is ambiguous", r.Attempts, r.Interval, r.Unlimited)) + multierror.Append(&mErr, errors.New("If Attempts >0, Unlimited cannot also be set to true")) } } @@ -5686,6 +5687,7 @@ func (a *Allocation) RescheduleEligible(reschedulePolicy *ReschedulePolicy, fail if reschedulePolicy.Unlimited { return true } + // Early return true if there are no attempts yet and the number of allowed attempts is > 0 if (a.RescheduleTracker == nil || len(a.RescheduleTracker.Events) == 0) && attempts > 0 { return true } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 9cb6b8520..442b4cedc 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -2226,7 +2226,7 @@ func TestReschedulePolicy_Validate(t *testing.T) { }, }, { - desc: "Ambiguous Unlimited config", + desc: "Ambiguous Unlimited config, has both attempts and unlimited set", ReschedulePolicy: &ReschedulePolicy{ Attempts: 1, Unlimited: true, @@ -2252,6 +2252,15 @@ func TestReschedulePolicy_Validate(t *testing.T) { fmt.Errorf("Max Delay cannot be less than %v (got %v)", ReschedulePolicyMinDelay, 0*time.Second), }, }, + { + desc: "Valid Unlimited config", + ReschedulePolicy: &ReschedulePolicy{ + Unlimited: true, + DelayFunction: "exponential", + Delay: 5 * time.Second, + MaxDelay: 1 * time.Hour, + }, + }, } for _, tc := range testCases {