@@ -22,6 +22,7 @@ import (
22
22
"reflect"
23
23
"time"
24
24
25
+ "golang.org/x/sync/errgroup"
25
26
v1 "k8s.io/api/coordination/v1"
26
27
v1alpha1 "k8s.io/api/coordination/v1alpha1"
27
28
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -264,6 +265,7 @@ func (c *Controller) reconcileElectionStep(ctx context.Context, leaseNN types.Na
264
265
265
266
now := c .clock .Now ()
266
267
canVoteYet := true
268
+ g , gCtx := errgroup .WithContext (ctx )
267
269
for _ , candidate := range candidates {
268
270
if candidate .Spec .PingTime != nil && candidate .Spec .PingTime .Add (electionDuration ).After (now ) &&
269
271
candidate .Spec .RenewTime != nil && candidate .Spec .RenewTime .Before (candidate .Spec .PingTime ) {
@@ -280,17 +282,18 @@ func (c *Controller) reconcileElectionStep(ctx context.Context, leaseNN types.Na
280
282
// If PingTime is outdated, send another PingTime only if it already acked the first one.
281
283
// This checks for pingTime <= renewTime because equality is possible in unit tests using a fake clock.
282
284
(candidate .Spec .PingTime .Add (electionDuration ).Before (now ) && ! candidate .Spec .RenewTime .Before (candidate .Spec .PingTime )) {
283
- // TODO(jefftree): We should randomize the order of sending pings and do them in parallel
284
- // so that all candidates have equal opportunity to ack.
285
285
clone := candidate .DeepCopy ()
286
286
clone .Spec .PingTime = & metav1.MicroTime {Time : now }
287
- _ , err := c . leaseCandidateClient . LeaseCandidates ( clone . Namespace ). Update ( ctx , clone , metav1. UpdateOptions {})
288
- if err != nil {
289
- return defaultRequeueInterval , err
290
- }
287
+ g . Go ( func () error {
288
+ _ , err := c . leaseCandidateClient . LeaseCandidates ( clone . Namespace ). Update ( gCtx , clone , metav1. UpdateOptions {})
289
+ return err
290
+ })
291
291
canVoteYet = false
292
292
}
293
293
}
294
+ if err := g .Wait (); err != nil {
295
+ return defaultRequeueInterval , err
296
+ }
294
297
if ! canVoteYet {
295
298
return defaultRequeueInterval , nil
296
299
}
0 commit comments