mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
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:
parent
a614056925
commit
10aab86051
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user