Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a leader election module #278

Open
multani opened this issue Jan 8, 2024 · 6 comments
Open

Provide a leader election module #278

multani opened this issue Jan 8, 2024 · 6 comments
Labels
enhancement New feature or request good second issue Clearly described and reproducible, but solution less clear than "good first issue" help wanted Extra attention is needed kr8s

Comments

@multani
Copy link

multani commented Jan 8, 2024

Which project are you requesting an enhancement for?

kr8s

What do you need?

Would it be possible to provide an out of the box module that implement leader election directly from kr8s?

The official Kubernetes client for Python provide some kind of implementation directly in the library: https://github.com/kubernetes-client/python/blob/master/kubernetes/base/leaderelection/ and there are well-known pattern to implement leader election using only core primitives of Kubernetes.

If this is something that kr8s would be willing to provide, I would be interested to contribute the feature :)

@multani multani added the enhancement New feature or request label Jan 8, 2024
@jacobtomlinson
Copy link
Member

Thanks for raising this @multani. This sounds like a really great feature to add to kr8s. I've never used the leader election modules in the other Kubernetes clients, but I think kubernetes is the only Python library that implements it so this would be another nice differentiating factor for kr8s.

Looking at the example in kubernetes I think we can definitely improve on the API too. Before you dive into code it would be great to have a discussion about the API here so we can find something that is readable and feels pythonic. We would also need to think about any differences there might be between a sync and async API as we will need to provide both.

@jacobtomlinson
Copy link
Member

It also looks like the official Python client uses the previous control-plane.alpha.kubernetes.io/leader annotation on a ConfigMap approach to leadership election. This has been superseded by Lease resources in the coordination.k8s.io/v1 API which is beta in Kubernetes 1.26+. Our minimum supported version is 1.26 so we are fine to go ahead and use this.

@multani
Copy link
Author

multani commented Jan 9, 2024

It looks like the official Python client implementation is more like a "demo" rather than a production ready implementation, but I think it's a good idea to offer this mechanism out of the box.

Looking at the example in kubernetes I think we can definitely improve on the API too. Before you dive into code it would be great to have a discussion about the API here so we can find something that is readable and feels pythonic. We would also need to think about any differences there might be between a sync and async API as we will need to provide both.

I'm interested to take a look at this and try to sketch up something that would be nice to use and would offer both sync and async APIs.

I did a similar experiment on top of Consul's lock/session APIs several months ago, I can come back in a couple of days with some ideas how it could look like using Kubernetes mechanisms instead 👍

@jacobtomlinson
Copy link
Member

I can come back in a couple of days with some ideas how it could look like using Kubernetes mechanisms instead

Sounds great!

@jacobtomlinson
Copy link
Member

@multani I assume you got busy, it happens! I'm going to drop the assignment and add the "help wanted" label in case anyone else wants to pick it up.

@jacobtomlinson jacobtomlinson added the help wanted Extra attention is needed label Mar 13, 2024
@multani
Copy link
Author

multani commented Mar 13, 2024

@jacobtomlinson yes, that's fair 🙇 I still plan to take a look, but it took a bit longer than expected and I've been busy with other things.

If someone else wants to move this forward, that would also be awesome!

@jacobtomlinson jacobtomlinson added the good second issue Clearly described and reproducible, but solution less clear than "good first issue" label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good second issue Clearly described and reproducible, but solution less clear than "good first issue" help wanted Extra attention is needed kr8s
Projects
None yet
Development

No branches or pull requests

2 participants