Class LeaderElector
Inheritance
LeaderElector
Assembly: KubernetesClient.dll
Syntax
public class LeaderElector : IDisposable
Constructors
View Source
LeaderElector(LeaderElectionConfig)
Declaration
public LeaderElector(LeaderElectionConfig config)
Parameters
Methods
View Source
Dispose()
Declaration
View Source
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type |
Name |
Description |
| bool |
disposing |
|
View Source
GetLeader()
Declaration
public string GetLeader()
Returns
View Source
IsLeader()
Declaration
Returns
View Source
RunAndTryToHoldLeadershipForeverAsync(CancellationToken)
Tries to acquire leadership via a Kubernetes Lease resource.
Will retry to acquire leadership again after leadership was lost.
Declaration
public Task RunAndTryToHoldLeadershipForeverAsync(CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| CancellationToken |
cancellationToken |
A token to cancel the operation.
|
Returns
| Type |
Description |
| Task |
A Task which completes only on cancellation
|
View Source
RunAsync(CancellationToken)
Tries to acquire leadership once via a Kubernetes Lease resource.
Will complete the returned Task and not retry to acquire leadership again after leadership is lost once.
Declaration
[Obsolete("Replaced by RunUntilLeadershipLostAsync to encode behavior in method name.")]
public Task RunAsync(CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| CancellationToken |
cancellationToken |
A token to cancel the operation.
|
Returns
| Type |
Description |
| Task |
A Task representing the asynchronous operation.
|
See Also
View Source
RunUntilLeadershipLostAsync(CancellationToken)
Tries to acquire and hold leadership once via a Kubernetes Lease resource.
Will complete the returned Task and not retry to acquire leadership again after leadership is lost once.
Declaration
public Task RunUntilLeadershipLostAsync(CancellationToken cancellationToken = default)
Parameters
| Type |
Name |
Description |
| CancellationToken |
cancellationToken |
A token to cancel the operation.
|
Returns
| Type |
Description |
| Task |
A Task representing the asynchronous operation.
|
Events
View Source
OnError
OnError is called when there is an error trying to determine leadership.
Declaration
public event Action<Exception> OnError
Event Type
View Source
OnNewLeader
OnNewLeader is called when the client observes a leader that is
not the previously observed leader. This includes the first observed
leader when the client starts.
Declaration
public event Action<string> OnNewLeader
Event Type
View Source
OnStartedLeading
OnStartedLeading is called when a LeaderElector client starts leading
Declaration
public event Action OnStartedLeading
Event Type
View Source
OnStoppedLeading
OnStoppedLeading is called when a LeaderElector client stops leading
Declaration
public event Action OnStoppedLeading
Event Type
Implements