mirror of https://github.com/k3s-io/k3s
leaderelection: set timeout for tryAcquireOrRenew
parent
7c6213e922
commit
90b287c12d
|
@ -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) {
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in New Issue