java icon indicating copy to clipboard operation
java copied to clipboard

Leader Elector shutdown delegated controller beside it cannot re-elect after renew failed

Open ilozano2 opened this issue 2 years ago • 2 comments
trafficstars

Similar to https://github.com/kubernetes-client/java/issues/714 I found that the controller is also shutdown after the renew fails, so even if I loop the leaderElector.run(..) code the DefaultController.run() will do nothing because it will also end its worker loop .

Adding a while(..) loop in my own LeaderElectingController as suggested in this comment will not work at all. The shutdown will make the delegateController useless.

while(continueLeadElection) {
    this.leaderElector.run(
        () -> {
          log.info("Lease acquired, starting controller..");
          this.delegateController.run();
        },
        () -> {
          log.info("Lease lost, shutting down controller..");
          this.delegateController.shutdown();
        });
}

As you can see, using delegateController = DefaultController instance will call the shutdown() method, which will turn off the queue. And, there is no way to re-activate the queue in case the old leader is elected again.

I suspect I will need to add the creation of my DefaultController instance in the loop process, but I am not sure if this is a good idea at all with all the pieces working underneath.

ilozano2 avatar Aug 03 '23 07:08 ilozano2