diff --git a/pkg/registry/core/service/ipallocator/controller/repair.go b/pkg/registry/core/service/ipallocator/controller/repair.go index ba4ce975582..d222d0e8699 100644 --- a/pkg/registry/core/service/ipallocator/controller/repair.go +++ b/pkg/registry/core/service/ipallocator/controller/repair.go @@ -156,13 +156,14 @@ func (c *Repair) doRunOnce() error { snapshotByFamily := make(map[v1.IPFamily]*api.RangeAllocation) storedByFamily := make(map[v1.IPFamily]ipallocator.Interface) - err := wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) { for family, allocator := range c.allocatorByFamily { // get snapshot if it is not there if _, ok := snapshotByFamily[family]; !ok { snapshot, err := allocator.Get() if err != nil { - return false, err + runtime.HandleError(fmt.Errorf("unable to refresh the service IP block: %w", err)) + return false, nil } snapshotByFamily[family] = snapshot @@ -172,7 +173,7 @@ func (c *Repair) doRunOnce() error { }) if err != nil { - return fmt.Errorf("unable to refresh the service IP block: %v", err) + return fmt.Errorf("unable to refresh the service IP block: %w", err) } // ensure that ranges are assigned diff --git a/pkg/registry/core/service/portallocator/controller/repair.go b/pkg/registry/core/service/portallocator/controller/repair.go index e76695a4c0f..0ec22c55a54 100644 --- a/pkg/registry/core/service/portallocator/controller/repair.go +++ b/pkg/registry/core/service/portallocator/controller/repair.go @@ -112,14 +112,17 @@ func (c *Repair) doRunOnce() error { // If etcd server is not running we should wait for some time and fail only then. This is particularly // important when we start apiserver and etcd at the same time. var snapshot *api.RangeAllocation - - err := wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) { - var err error + var err error + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) { snapshot, err = c.alloc.Get() - return err == nil, err + if err != nil { + runtime.HandleError(fmt.Errorf("unable to refresh the port allocations: %w", err)) + return false, nil + } + return true, nil }) if err != nil { - return fmt.Errorf("unable to refresh the port allocations: %v", err) + return fmt.Errorf("unable to refresh the port allocations: %w", err) } // If not yet initialized. if snapshot.Range == "" {