Class KubernetesLeaderElector

java.lang.Object
org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector

public class KubernetesLeaderElector extends Object
Represent KubernetesLeaderElector in kubernetes. LeaderElector.run() is a blocking call. It should be run in the IO executor, not the main thread. The lifecycle is bound to single leader election. Once the leadership is revoked, as well as the KubernetesLeaderElector.LeaderCallbackHandler.notLeader() is called, the LeaderElector.run() will finish. To start another round of election, we need to trigger again.

LeaderElector.run() is responsible for creating the leader ConfigMap and continuously update the annotation. The annotation key is LEADER_ANNOTATION_KEY and the value is in the following json format. metadata: annotations: control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"623e39fb-70c3-44f1-811f-561ec4a28d75","leaseDuration":15.000000000,"acquireTime":"2020-10-20T04:06:31.431000Z","renewTime":"2020-10-22T08:51:36.843000Z","leaderTransitions":37981}'