litefs icon indicating copy to clipboard operation
litefs copied to clipboard

Support Kubernetes Lease API

Open arianvp opened this issue 1 year ago • 7 comments

Kubernetes has something similar to consul sessions called the Lease API. Could we use it to simplify deployments in k8s so there is no dependency on consul?

arianvp avatar Jul 26 '22 19:07 arianvp

I didn't realize there was a Kubernetes Lease API. That's good to know. Yes, I think supporting that would be great. I'll tackle that once I get the project stabilized and tested. Thanks!

benbjohnson avatar Jul 26 '22 19:07 benbjohnson

Following

phillamb168 avatar Aug 11 '22 17:08 phillamb168

@phillamb168 Just as a heads up there should be a "Subscribe" button on the right side of the PR if you want to get future notifications.

Screen Shot 2022-08-11 at 11 21 05 AM

benbjohnson avatar Aug 11 '22 17:08 benbjohnson

By the way here is the upstream example:

https://github.com/kubernetes/client-go/blob/v0.25.2/examples/leader-election/main.go

It uses a built-in leader elector loop which is maybe not what you want. So probably have to peek into https://github.com/kubernetes/client-go/blob/2fd4aac19007b97ef5b22d045b5615e2094200a1/tools/leaderelection/leaderelection.go#L243 and see how to hook it into litefs' loop

arianvp avatar Sep 22 '22 11:09 arianvp

@arianvp Thanks for the example code. It looks like the loop is handled by the Kubernetes client and acquire() and renew() isn't accessible. I'll need to refactor the LiteFS code a bit so it can externalize the loop instead of handling it itself.

benbjohnson avatar Sep 22 '22 16:09 benbjohnson

acquireOrRenew is implemented in terms of only public functions. So perhaps it's worth looking at its impl and mimicking it if you want to keep your own loop

https://github.com/kubernetes/client-go/blob/2fd4aac19007b97ef5b22d045b5615e2094200a1/tools/leaderelection/leaderelection.go#L317

But reusing the kubernetes loop might probably be more robust.

arianvp avatar Sep 22 '22 18:09 arianvp

Just wanted to give a more visible thumbs up to this feature request.

I know people also want etcd and Zookeeper, and you mentioned this is lower priority, but at least I thought I would ask in case priorities have changed or if you have new opinions about this.

casidiablo avatar Apr 14 '24 06:04 casidiablo