Commit 90b287c1 authored by xuzhonghu's avatar xuzhonghu

leaderelection: set timeout for tryAcquireOrRenew

parent 7c6213e9
...@@ -204,7 +204,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) { ...@@ -204,7 +204,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) {
} }
// prepare kube clients. // 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 { if err != nil {
return nil, err return nil, err
} }
......
...@@ -207,8 +207,20 @@ func (le *LeaderElector) renew(ctx context.Context) { ...@@ -207,8 +207,20 @@ func (le *LeaderElector) renew(ctx context.Context) {
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline) timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline)
defer timeoutCancel() defer timeoutCancel()
err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) { 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()) }, timeoutCtx.Done())
le.maybeReportTransition() le.maybeReportTransition()
desc := le.config.Lock.Describe() desc := le.config.Lock.Describe()
if err == nil { if err == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment