superfly / litefs

FUSE-based file system for replicating SQLite databases across a cluster of machines
Apache License 2.0
4.04k stars 96 forks source link

Support Kubernetes Lease API #23

Open arianvp opened 2 years ago

arianvp commented 2 years ago

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?

benbjohnson commented 2 years ago

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!

phillamb168 commented 2 years ago

Following

benbjohnson commented 2 years ago

@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
arianvp commented 2 years ago

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

benbjohnson commented 2 years ago

@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.

arianvp commented 2 years ago

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.

casidiablo commented 6 months ago

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.