Skip to content

Commit fa75c8c

Browse files
authored
Merge pull request kubernetes#126671 from fusida/fix-ipallocator-repair-timeout
set service-ip-repair-controller wait time match with etcd dial timeout
2 parents 0a406ee + fc07c23 commit fa75c8c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pkg/registry/core/service/ipallocator/controller/repair.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ func (c *Repair) doRunOnce() error {
156156
snapshotByFamily := make(map[v1.IPFamily]*api.RangeAllocation)
157157
storedByFamily := make(map[v1.IPFamily]ipallocator.Interface)
158158

159-
err := wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) {
159+
err := wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) {
160160
for family, allocator := range c.allocatorByFamily {
161161
// get snapshot if it is not there
162162
if _, ok := snapshotByFamily[family]; !ok {
163163
snapshot, err := allocator.Get()
164164
if err != nil {
165-
return false, err
165+
runtime.HandleError(fmt.Errorf("unable to refresh the service IP block: %w", err))
166+
return false, nil
166167
}
167168

168169
snapshotByFamily[family] = snapshot
@@ -172,7 +173,7 @@ func (c *Repair) doRunOnce() error {
172173
})
173174

174175
if err != nil {
175-
return fmt.Errorf("unable to refresh the service IP block: %v", err)
176+
return fmt.Errorf("unable to refresh the service IP block: %w", err)
176177
}
177178

178179
// ensure that ranges are assigned

pkg/registry/core/service/portallocator/controller/repair.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ func (c *Repair) doRunOnce() error {
112112
// If etcd server is not running we should wait for some time and fail only then. This is particularly
113113
// important when we start apiserver and etcd at the same time.
114114
var snapshot *api.RangeAllocation
115-
116-
err := wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) {
117-
var err error
115+
var err error
116+
err = wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) {
118117
snapshot, err = c.alloc.Get()
119-
return err == nil, err
118+
if err != nil {
119+
runtime.HandleError(fmt.Errorf("unable to refresh the port allocations: %w", err))
120+
return false, nil
121+
}
122+
return true, nil
120123
})
121124
if err != nil {
122-
return fmt.Errorf("unable to refresh the port allocations: %v", err)
125+
return fmt.Errorf("unable to refresh the port allocations: %w", err)
123126
}
124127
// If not yet initialized.
125128
if snapshot.Range == "" {

0 commit comments

Comments
 (0)