mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-11-30 23:16:04 +07:00
aggregate masq sync errors
This commit is contained in:
@@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -55,23 +56,23 @@ type IPMasqAgent struct {
|
||||
// SyncRulesForever syncs ip masquerade rules forever
|
||||
// these rules only needs to be installed once, but we run it periodically to check that are
|
||||
// not deleted by an external program. It fails if can't sync the rules during 3 iterations
|
||||
// TODO: aggregate errors
|
||||
func (ma *IPMasqAgent) SyncRulesForever(ctx context.Context, interval time.Duration) error {
|
||||
errs := 0
|
||||
var errs []error
|
||||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
if err := ma.SyncRules(); err != nil {
|
||||
errs++
|
||||
if errs > 3 {
|
||||
return fmt.Errorf("Can't synchronize rules after 3 attempts: %v", err)
|
||||
errs = append(errs, fmt.Errorf("failed to synchronize rules at %s: %v", time.Now(), err))
|
||||
if len(errs) > 3 {
|
||||
return fmt.Errorf("Can't synchronize rules after 3 attempts: %w", err)
|
||||
}
|
||||
} else {
|
||||
errs = 0
|
||||
errs = errs[:0]
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return errors.Join(errs...)
|
||||
case <-ticker.C:
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user