@@ -14,7 +14,7 @@ import (
1414 "strings"
1515 "time"
1616
17- "github.com/avast/retry-go/v4 "
17+ "github.com/avast/retry-go/v5 "
1818
1919 "github.com/bpg/terraform-provider-proxmox/proxmox/api"
2020 "github.com/bpg/terraform-provider-proxmox/utils/ip"
@@ -169,7 +169,26 @@ func (c *Client) WaitForContainerNetworkInterfaces(
169169 ctxWithTimeout , cancel := context .WithTimeout (ctx , timeout )
170170 defer cancel ()
171171
172- ifaces , err := retry .DoWithData (
172+ ifaces , err := retry .NewWithData [[]GetNetworkInterfacesData ](
173+ retry .Context (ctxWithTimeout ),
174+ retry .RetryIf (func (err error ) bool {
175+ var target * api.HTTPError
176+ if errors .As (err , & target ) {
177+ if target .Code == http .StatusBadRequest {
178+ // this is a special case to account for eventual consistency
179+ // when creating a task -- the task may not be available via status API
180+ // immediately after creation
181+ return true
182+ }
183+ }
184+
185+ return errors .Is (err , api .ErrNoDataObjectInResponse ) || errors .Is (err , errNoIPsYet )
186+ }),
187+ retry .LastErrorOnly (true ),
188+ retry .UntilSucceeded (),
189+ retry .DelayType (retry .FixedDelay ),
190+ retry .Delay (time .Second ),
191+ ).Do (
173192 func () ([]GetNetworkInterfacesData , error ) {
174193 ifaces , err := c .GetContainerNetworkInterfaces (ctx )
175194 if err != nil {
@@ -207,24 +226,6 @@ func (c *Client) WaitForContainerNetworkInterfaces(
207226 // all required IP types are available
208227 return ifaces , nil
209228 },
210- retry .Context (ctxWithTimeout ),
211- retry .RetryIf (func (err error ) bool {
212- var target * api.HTTPError
213- if errors .As (err , & target ) {
214- if target .Code == http .StatusBadRequest {
215- // this is a special case to account for eventual consistency
216- // when creating a task -- the task may not be available via status API
217- // immediately after creation
218- return true
219- }
220- }
221-
222- return errors .Is (err , api .ErrNoDataObjectInResponse ) || errors .Is (err , errNoIPsYet )
223- }),
224- retry .LastErrorOnly (true ),
225- retry .UntilSucceeded (),
226- retry .DelayType (retry .FixedDelay ),
227- retry .Delay (time .Second ),
228229 )
229230 if errors .Is (err , context .DeadlineExceeded ) {
230231 return nil , errors .New ("timeout while waiting for container IP addresses" )
@@ -408,7 +409,15 @@ func (c *Client) WaitForContainerStatus(ctx context.Context, status string) erro
408409
409410 unexpectedStatus := fmt .Errorf ("unexpected status %q" , status )
410411
411- err := retry .Do (
412+ err := retry .New (
413+ retry .Context (ctx ),
414+ retry .RetryIf (func (err error ) bool {
415+ return errors .Is (err , unexpectedStatus )
416+ }),
417+ retry .UntilSucceeded (),
418+ retry .Delay (1 * time .Second ),
419+ retry .LastErrorOnly (true ),
420+ ).Do (
412421 func () error {
413422 data , err := c .GetContainerStatus (ctx )
414423 if err != nil {
@@ -421,13 +430,6 @@ func (c *Client) WaitForContainerStatus(ctx context.Context, status string) erro
421430
422431 return nil
423432 },
424- retry .Context (ctx ),
425- retry .RetryIf (func (err error ) bool {
426- return errors .Is (err , unexpectedStatus )
427- }),
428- retry .UntilSucceeded (),
429- retry .Delay (1 * time .Second ),
430- retry .LastErrorOnly (true ),
431433 )
432434 if errors .Is (err , context .DeadlineExceeded ) {
433435 return fmt .Errorf ("timeout while waiting for container %d to enter the status %q" , c .VMID , status )
@@ -444,7 +446,15 @@ func (c *Client) WaitForContainerStatus(ctx context.Context, status string) erro
444446func (c * Client ) WaitForContainerConfigUnlock (ctx context.Context , ignoreErrorResponse bool ) error {
445447 stillLocked := errors .New ("still locked" )
446448
447- err := retry .Do (
449+ err := retry .New (
450+ retry .Context (ctx ),
451+ retry .RetryIf (func (err error ) bool {
452+ return errors .Is (err , stillLocked ) || ignoreErrorResponse
453+ }),
454+ retry .UntilSucceeded (),
455+ retry .Delay (1 * time .Second ),
456+ retry .LastErrorOnly (true ),
457+ ).Do (
448458 func () error {
449459 data , err := c .GetContainerStatus (ctx )
450460 if err != nil {
@@ -457,13 +467,6 @@ func (c *Client) WaitForContainerConfigUnlock(ctx context.Context, ignoreErrorRe
457467
458468 return nil
459469 },
460- retry .Context (ctx ),
461- retry .RetryIf (func (err error ) bool {
462- return errors .Is (err , stillLocked ) || ignoreErrorResponse
463- }),
464- retry .UntilSucceeded (),
465- retry .Delay (1 * time .Second ),
466- retry .LastErrorOnly (true ),
467470 )
468471 if errors .Is (err , context .DeadlineExceeded ) {
469472 return fmt .Errorf ("timeout while waiting for container %d configuration to become unlocked" , c .VMID )
0 commit comments