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

Add kubernetes election module #3721

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

osmman
Copy link

@osmman osmman commented Jan 27, 2025

This PR adds a new leader election implementation using the Kubernetes Lease API.

By leveraging Kubernetes Lease resources, this implementation provides an alternative backend for leader election. It simplifies deployments on Kubernetes by removing the need for a secondary etcd cluster when running Kubernetes workloads.

Fixes #3431

Checklist

Copy link

google-cla bot commented Jan 27, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@osmman osmman force-pushed the k8s-election branch 3 times, most recently from 922ebcf to 68897bf Compare January 27, 2025 16:29
Copy link
Contributor

@mhutchinson mhutchinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. Are you happy to be an owner of the new k8s election code module? The core team doesn't have the time or expertise to take on ownership of this. On the whole this role is largely being responsible for reviewing code changes from other users and any dependency updates that require code changes.

I've left some comments on the old code that was refactored to make space for this but I haven't reviewed the new code yet. I'm at a summit this week but this is on my radar for when I have time.

@@ -76,6 +74,7 @@ var (

storageSystem = flag.String("storage_system", provider.DefaultStorageSystem, fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))

electionSystem = flag.String("election_system", "etcd", fmt.Sprintf("Election systen ti use. One of: %v", election2.Providers()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
electionSystem = flag.String("election_system", "etcd", fmt.Sprintf("Election systen ti use. One of: %v", election2.Providers()))
electionSystem = flag.String("election_system", "etcd", fmt.Sprintf("Election system to use. One of: %v", election2.Providers()))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"time"
)

// ElectionName identifies the kubernetes election implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ElectionName identifies the kubernetes election implementation.
// ElectionName identifies the etcd election implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

)

func init() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there are a few places in this PR where you have a blank line after opening braces. Can you remove them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

hostname, _ := os.Hostname()
instanceID := fmt.Sprintf("%s.%d", hostname, os.Getpid())

servers := flag.Lookup("etcd_servers").Value.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flag.Lookup is a bit gnarly but I see that there aren't many other options without rearchitecting a lot of stuff.

Comment on lines 52 to 53
// NewFactory builds an election factory that uses the given parameters. The
// passed in etcd client should remain valid for the lifetime of the object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a bit stale.

@@ -0,0 +1,71 @@
// Copyright 2017 Google LLC. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The year is out of date in a number of new files.

Introduce a new election module using the Kubernetes Lease API. Modify
the existing mechanism to allow selection of election mechanisms by
introducing the `--election_system` parameter, following the same
pattern used for storage and quota system selection.
@osmman
Copy link
Author

osmman commented Jan 31, 2025

Thanks for this PR. Are you happy to be an owner of the new k8s election code module? The core team doesn't have the time or expertise to take on ownership of this. On the whole this role is largely being responsible for reviewing code changes from other users and any dependency updates that require code changes.

Yes, I can take ownership

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leader election using Kubernetes leases
2 participants