Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/KubernetesClient/LeaderElection/LeaderElector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class LeaderElector : IDisposable
/// </summary>
public event Action<string> OnNewLeader;

/// <summary>
/// OnError is called when there is an error trying to determine leadership.
/// </summary>
public event Action<Exception> OnError;

private volatile LeaderElectionRecord observedRecord;
private DateTimeOffset observedTime = DateTimeOffset.MinValue;
private string reportedLeader;
Expand Down Expand Up @@ -69,8 +74,9 @@ public async Task RunAsync(CancellationToken cancellationToken = default)
MaybeReportTransition();
}
}
catch
catch (Exception e)
{
OnError?.Invoke(e);
// ignore
return false;
}
Expand Down Expand Up @@ -129,6 +135,8 @@ private async Task<bool> TryAcquireOrRenew(CancellationToken cancellationToken)
{
return false;
}

OnError?.Invoke(e);
}

if (oldLeaderElectionRecord?.AcquireTime == null ||
Expand Down