leaderelection: set timeout for tryAcquireOrRenew

pull/8/head
xuzhonghu 2018-06-20 15:44:31 +08:00
parent 7c6213e922
commit 90b287c12d
2 changed files with 14 additions and 2 deletions

View File

@ -204,7 +204,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) {
}
// prepare kube clients.
client, leaderElectionClient, eventClient, err := createClients(o.ComponentConfig.ClientConnection, o.Master, o.ComponentConfig.LeaderElection.RenewDeadline.Duration)
client, leaderElectionClient, eventClient, err := createClients(c.ComponentConfig.ClientConnection, o.Master, c.ComponentConfig.LeaderElection.RenewDeadline.Duration)
if err != nil {
return nil, err
}

View File

@ -207,8 +207,20 @@ func (le *LeaderElector) renew(ctx context.Context) {
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline)
defer timeoutCancel()
err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) {
return le.tryAcquireOrRenew(), nil
done := make(chan bool, 1)
go func() {
defer close(done)
done <- le.tryAcquireOrRenew()
}()
select {
case <-timeoutCtx.Done():
return false, fmt.Errorf("failed to tryAcquireOrRenew %s", timeoutCtx.Err())
case result := <-done:
return result, nil
}
}, timeoutCtx.Done())
le.maybeReportTransition()
desc := le.config.Lock.Describe()
if err == nil {