mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
Add retries to runner.List()
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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) {
|
||||
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)
|
||||
if err != nil {
|
||||
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")
|
||||
|
Reference in New Issue
Block a user