Skip to content

Commit

Permalink
refactor DoUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasferrandiz committed Nov 20, 2024
1 parent d47cdcc commit aaf6cc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Do(f func() error) error {

}

func DoUntil(f func() error, ctx context.Context, timeout time.Duration) error {
func DoUntil(ctx context.Context, f func() error, timeout time.Duration) error {
toctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return retry_v4.Do(f,
Expand Down
21 changes: 10 additions & 11 deletions pkg/trafficmngr/iptables/iptables_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ func (iptr *ipTablesRestore) ApplyWithoutFlush(ctx context.Context, rules IPTabl

log.V(6).Infof("trying to run iptables-restore with payload %s", payload)

err := retry.DoUntil(func() error {
stdout, stderr, err := iptr.runWithOutput([]string{"--noflush"}, bytes.NewBuffer([]byte(payload)))
if err != nil {
log.Errorf("iptables-restore finished with error: %v", err)
log.Errorf("stdout: %s", stdout)
log.Errorf("stderr: %s", stderr)

}
return err
},
ctx,
err := retry.DoUntil(ctx,
func() error {
stdout, stderr, err := iptr.runWithOutput([]string{"--noflush"}, bytes.NewBuffer([]byte(payload)))
if err != nil {
log.Errorf("iptables-restore finished with error: %v", err)
log.Errorf("stdout: %s", stdout)
log.Errorf("stderr: %s", stderr)
}
return err
},
iptRestoreTimeout*time.Second)

if err != nil {
Expand Down

0 comments on commit aaf6cc7

Please sign in to comment.