Skip to content

Commit 7454f04

Browse files
authored
add onerr callback for leader elector (#1399)
1 parent 8e19c03 commit 7454f04

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/KubernetesClient/LeaderElection/LeaderElector.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class LeaderElector : IDisposable
2828
/// </summary>
2929
public event Action<string> OnNewLeader;
3030

31+
/// <summary>
32+
/// OnError is called when there is an error trying to determine leadership.
33+
/// </summary>
34+
public event Action<Exception> OnError;
35+
3136
private volatile LeaderElectionRecord observedRecord;
3237
private DateTimeOffset observedTime = DateTimeOffset.MinValue;
3338
private string reportedLeader;
@@ -69,8 +74,9 @@ public async Task RunAsync(CancellationToken cancellationToken = default)
6974
MaybeReportTransition();
7075
}
7176
}
72-
catch
77+
catch (Exception e)
7378
{
79+
OnError?.Invoke(e);
7480
// ignore
7581
return false;
7682
}
@@ -129,6 +135,8 @@ private async Task<bool> TryAcquireOrRenew(CancellationToken cancellationToken)
129135
{
130136
return false;
131137
}
138+
139+
OnError?.Invoke(e);
132140
}
133141

134142
if (oldLeaderElectionRecord?.AcquireTime == null ||

0 commit comments

Comments
 (0)