Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class KubernetesLeaderElector {
@VisibleForTesting
public static final String LEADER_ANNOTATION_KEY = "control-plane.alpha.kubernetes.io/leader";

private final Object lock = new Object();

private final ExecutorService executorService =
Executors.newSingleThreadExecutor(
new ExecutorThreadFactory("KubernetesLeaderElector-ExecutorService"));
Expand Down Expand Up @@ -92,11 +94,20 @@ public KubernetesLeaderElector(
}

public void run() {
executorService.submit(internalLeaderElector::run);
synchronized (lock) {
if (executorService.isShutdown()) {
LOG.debug(
"Ignoring KubernetesLeaderElector.run call because the leader elector has already been shut down.");
} else {
executorService.execute(internalLeaderElector::run);
}
}
}

public void stop() {
executorService.shutdownNow();
synchronized (lock) {
executorService.shutdownNow();
}
}

public static boolean hasLeadership(KubernetesConfigMap configMap, String lockIdentity) {
Expand Down