Class LeaderElector<C extends Namespaceable<C> & KubernetesClient>

    • Field Detail

      • JITTER_FACTOR

        protected static final Double JITTER_FACTOR
    • Constructor Detail

      • LeaderElector

        public LeaderElector​(C kubernetesClient,
                             LeaderElectionConfig leaderElectionConfig)
    • Method Detail

      • run

        public void run()
        Starts the leader election loop
      • canBecomeLeader

        protected final boolean canBecomeLeader​(LeaderElectionRecord leaderElectionRecord)
      • loop

        protected static boolean loop​(Consumer<CountDownLatch> consumer,
                                      long periodInMillis)
        Periodically (every provided period) runs the provided Consumer in a separate thread causing the current thread to wait until the supplied CountDownLatch is decremented by 1 unit.
        Parameters:
        consumer - function to run in a separate thread
        periodInMillis - to schedule the run of the provided consumer
        Returns:
        true if the current thread was not interrupted, false otherwise
      • jitter

        protected static Duration jitter​(Duration duration,
                                         double maxFactor)
        Returns a Duration between the provided duration and (duration + maxFactor*duration)
        Parameters:
        duration - to apply jitter to
        maxFactor - for jitter
        Returns:
        the jittered duration