Add retries to runner.List()

This commit is contained in:
Adrian Moisey
2025-01-30 20:09:46 +02:00
parent b6f49d0728
commit faf6dc1313
2 changed files with 14 additions and 5 deletions

View File

@@ -31,6 +31,6 @@ type Interface interface {
Add(name string) error
// Get retrieves the nfacct counter with the specified name, returning an error if it doesn't exist.
Get(name string) (*Counter, error)
// List retrieves all nfacct counters.
// List retrieves nfacct counters, it could receive all counters or a subset of them with an unix.EINTR error.
List() ([]*Counter, error)
}

View File

@@ -29,6 +29,9 @@ import (
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
"k8s.io/client-go/util/retry"
"k8s.io/kubernetes/pkg/proxy/util"
)
// MaxLength represents the maximum length allowed for the name in a nfacct counter.
@@ -146,9 +149,15 @@ func (r *runner) Get(name string) (*Counter, error) {
// List is part of the interface.
func (r *runner) List() ([]*Counter, error) {
req := r.handler.newRequest(cmdGet, unix.NLM_F_REQUEST|unix.NLM_F_DUMP)
msgs, err := req.Execute(unix.NETLINK_NETFILTER, 0)
if err != nil {
var err error
var msgs [][]byte
err = retry.OnError(util.MaxAttemptsEINTR, util.ShouldRetryOnEINTR, func() error {
req := r.handler.newRequest(cmdGet, unix.NLM_F_REQUEST|unix.NLM_F_DUMP)
msgs, err = req.Execute(unix.NETLINK_NETFILTER, 0)
return err
})
if err != nil && !errors.Is(err, unix.EINTR) {
return nil, handleError(err)
}
@@ -160,7 +169,7 @@ func (r *runner) List() ([]*Counter, error) {
}
counters = append(counters, counter)
}
return counters, nil
return counters, err
}
var ErrObjectNotFound = errors.New("object not found")