Make sure we use MaxRetries correctly

Even if MaxRetries is 0, we should still execute the loop one time in
order to run the Chef-Client at least once. Also waiting only makes
sense when we have `attempts` left. And last but not least we want to
exit immediately when the exit code is not in the retry list.

So this PR fixes three small issues to make everything work as
expected.
This commit is contained in:
Sander van Harmelen 2020-05-05 15:29:52 +02:00 committed by Brian Dwyer
parent a614056925
commit 10aab86051
1 changed files with 6 additions and 2 deletions

View File

@ -391,7 +391,7 @@ func applyFn(ctx context.Context) error {
o.Output("Starting initial Chef-Client run...")
for attempt := 0; attempt < p.MaxRetries; attempt++ {
for attempt := 0; attempt <= p.MaxRetries; attempt++ {
// Make sure to (re)connect before trying to run Chef-Client.
if err := communicator.Retry(retryCtx, func() error {
return comm.Connect(o)
@ -423,7 +423,11 @@ func applyFn(ctx context.Context) error {
err = nil
}
if p.RetryOnExitCode[exitError.ExitStatus] {
if !p.RetryOnExitCode[exitError.ExitStatus] {
return err
}
if attempt < p.MaxRetries {
o.Output(fmt.Sprintf("Waiting %s before retrying Chef-Client run...", p.WaitForRetry))
time.Sleep(p.WaitForRetry)
}