Skip to content

Commit 595cf09

Browse files
committed
docs
1 parent 144947d commit 595cf09

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

docs/documentation/features.md

+12
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,18 @@ See also
683683
the [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/ec37025a15046d8f409c77616110024bf32c3416/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java)
684684
for this feature.
685685

686+
## Leader Election
687+
688+
In general operators are deployed with single instance running, or a single active instance running. That means
689+
if multiple instances are deployed only one of the should process the events. This is achieved by configuring leader
690+
election. Leader election will make sure only one instance of the operator is processing events, other instances will
691+
start event sources, where those will populate the caches - this is beneficial for the case the instance becomes the
692+
leader it will start reconcile immediately, and don't have to wait until the event sources are started and
693+
caches are populated.
694+
695+
See sample configuration in the [E2E test](https://github.com/java-operator-sdk/java-operator-sdk/blob/144947d89323f1c65de6e86bd8b9a6a8ffe714ff/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java#L26-L30)
696+
.
697+
686698
## Monitoring with Micrometer
687699
688700
## Automatic Generation of CRDs

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public void start() {
9999
final var clientVersion = Version.clientVersion();
100100
log.info("Client version: {}", clientVersion);
101101
ExecutorServiceManager.init();
102+
// first start the controller manager before leader election,
103+
// the leader election would start subsequently the processor if on
102104
controllerManager.start(!leaderElectionManager.isLeaderElectionOn());
103105
leaderElectionManager.start();
104106
} catch (Exception e) {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfiguration.java

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ public class LeaderElectionConfiguration {
99
public static final Duration RENEW_DEADLINE_DEFAULT_VALUE = Duration.ofSeconds(10);
1010
public static final Duration RETRY_PERIOD_DEFAULT_VALUE = Duration.ofSeconds(2);
1111

12-
// todo discuss
13-
// private boolean syncEventSources;
14-
1512
private final String leaseName;
1613
private final String leaseNamespace;
1714
private final String identity;

sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class LeaderElectionTestOperator {
1313
private static final Logger log = LoggerFactory.getLogger(LeaderElectionTestOperator.class);
1414

1515
public static void main(String[] args) {
16-
System.out.println("Starting...");
1716
String identity = System.getenv("POD_NAME");
1817
String namespace = System.getenv("POD_NAMESPACE");
1918

sample-operators/leader-election/src/main/resources/log4j2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
<AppenderRef ref="Console"/>
1111
</Root>
1212
</Loggers>
13-
</Configuration>
13+
</Configuration>

sample-operators/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
<module>mysql-schema</module>
2525
<module>leader-election</module>
2626
</modules>
27-
</project>
27+
</project>

0 commit comments

Comments
 (0)