Skip to content

Commit

Permalink
Merge pull request #3771 from sword-jin/aggregate_masq_sync_errors
Browse files Browse the repository at this point in the history
aggregate masq sync errors
  • Loading branch information
k8s-ci-robot authored Oct 31, 2024
2 parents 287d740 + 23d571e commit 4f444f8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions images/kindnetd/cmd/kindnetd/masq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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:
}
}
Expand Down

0 comments on commit 4f444f8

Please sign in to comment.