File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -11,16 +11,19 @@ internal class ResourceControllerManager : IHostedService
11
11
{
12
12
private readonly IControllerInstanceBuilder _controllerInstanceBuilder ;
13
13
private readonly ILeaderElection _leaderElection ;
14
+ private readonly OperatorSettings _operatorSettings ;
14
15
private readonly List < IManagedResourceController > _controllerList ;
15
16
16
17
private IDisposable ? _leadershipSubscription ;
17
18
18
19
public ResourceControllerManager (
19
20
IControllerInstanceBuilder controllerInstanceBuilder ,
20
- ILeaderElection leaderElection )
21
+ ILeaderElection leaderElection ,
22
+ OperatorSettings operatorSettings )
21
23
{
22
24
_controllerInstanceBuilder = controllerInstanceBuilder ;
23
25
_leaderElection = leaderElection ;
26
+ _operatorSettings = operatorSettings ;
24
27
_controllerList = new List < IManagedResourceController > ( ) ;
25
28
}
26
29
@@ -54,7 +57,8 @@ private void LeadershipChanged(LeaderState state)
54
57
55
58
foreach ( var controller in _controllerList )
56
59
{
57
- if ( state == LeaderState . Leader )
60
+ if ( state == LeaderState . Leader
61
+ || ! _operatorSettings . OnlyWatchEventsWhenLeader )
58
62
{
59
63
controller . StartAsync ( ) ;
60
64
}
Original file line number Diff line number Diff line change @@ -94,6 +94,22 @@ public sealed class OperatorSettings
94
94
/// </summary>
95
95
public bool EnableLeaderElection { get ; set ; } = true ;
96
96
97
+ /// <summary>
98
+ /// <para>
99
+ /// If set to true, controllers will only watch for new events when in a leader state,
100
+ /// or if leadership is disabled. When false, this check is disabled,
101
+ /// controllers will always watch for resource changes regardless of leadership state.
102
+ /// </para>
103
+ /// <para>
104
+ /// If this is disabled, you should consider checking leadership state manually,
105
+ /// to prevent a "split brain" problem.
106
+ /// </para>
107
+ /// <para>
108
+ /// Defaults to true.
109
+ /// </para>
110
+ /// </summary>
111
+ public bool OnlyWatchEventsWhenLeader { get ; set ; } = true ;
112
+
97
113
/// <summary>
98
114
/// The interval in seconds in which this particular instance of the operator
99
115
/// will check for leader election.
You can’t perform that action at this time.
0 commit comments