Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: Force Lease Expiration When Leader Exits#2379

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
RaghavRoy145 wants to merge1 commit intokubernetes-client:master
base:master
Choose a base branch
Loading
fromRaghavRoy145:leaderelection-fix

Conversation

RaghavRoy145
Copy link

@RaghavRoy145RaghavRoy145 commentedMar 30, 2025
edited
Loading

What type of PR is this?

/kind bug

What this PR does / why we need it:

Currently, when the leader exits (say, after receiving aSIGINT) the workers need to wait for its lease to expire before a leader is re-elected. This patch mimics the behaviour of the Go Client implementation of usingctx.Done():https://github.com/kubernetes/client-go/blob/1309f64d6648411b4a36a2f7fa84dd8df31884b6/tools/leaderelection/leaderelection.go#L265-L291. It captures theSIGINT and forces the lease to exit by setting the expiration to a date in the past, and it also sets theacquire_time to None to force a leader election.

  • Issue Reproduction

    As mentioned in the issue:leaderelection do not stop leading properly #2075, to reproduce this issue you can follow leaderelection/example.py. Run it on 2-3 nodes (or tmux screens) and once a leader is elected hitCtrl+C to force the leader to exit. The workers then wait for the leader's lease to expire before a new leader is elected.

  • Expected behavior

    The leader exiting should trigger a leader election without having the workers wait for the lease to expire.

Which issue(s) this PR fixes:

Fixes#2075

Special notes for your reviewer:

This is still not a complete fix. It is definitely hacky at the moment and I would love any guidance here! Currently, the patch only handlesSIGINT but a leader may exit for various reasons, and there should be a more elegant way of handling this. Probably using the thread context but I was not able to figure that out. Further, the implementation of theforce_expire_lease() function is not elegant; you shouldn't need to setacquire_time toNone and settingexpiration to the past is also a code smell in my opinion. This patch is a proof of concept because of this.

I also had to change the imports to point to my definitions ofelectionconfig.py andleaderelectionrecord.pyfor this to work and I'm sure there is a better way of handling this.

If its more sensible to mark this PR a draft, I'm happy to do so!

Does this PR introduce a user-facing change?

None

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

None

Currently, when the leader exits (say, after receiving a SIGINT),the workers need to wait for its lease to expire before a leaderis re-elected. This patch mimics the behaviour of the Go Client implementationof using ctx.Done() by capturing the SIGINT and forcing the expiration date to apast date and also sets the acquire_time to None to start the leader election.
@k8s-ci-robotk8s-ci-robot added release-note-noneDenotes a PR that doesn't merit a release note. kind/bugCategorizes issue or PR as related to a bug. labelsMar 30, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR isNOT APPROVED

This pull-request has been approved by:RaghavRoy145
Once this PR has been reviewed and has the lgtm label, please assignyliaog for approval. For more information seethe Code Review Process.

The full list of commands accepted by this bot can be foundhere.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing/approve in a comment
Approvers can cancel approval by writing/approve cancel in a comment

@k8s-ci-robotk8s-ci-robot added the cncf-cla: yesIndicates the PR's author has signed the CNCF CLA. labelMar 30, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome@RaghavRoy145!

It looks like this is your first PR tokubernetes-client/python 🎉. Please refer to ourpull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment.Here is the bot commands documentation.

You can also check if kubernetes-client/python hasits own contribution guidelines.

You may want to refer to ourtesting guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow therecommended escalation practices. Also, for tips and tricks in the contribution process you may want to read theKubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robotk8s-ci-robot added the size/MDenotes a PR that changes 30-99 lines, ignoring generated files. labelMar 30, 2025
@RaghavRoy145
Copy link
Author

/assign@yliaog

@RaghavRoy145
Copy link
Author

/assign@yliaog

Oops, I was supposed to do that after the reviews 🙃

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity,lifecycle/stale is applied
  • After 30d of inactivity sincelifecycle/stale was applied,lifecycle/rotten is applied
  • After 30d of inactivity sincelifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with/remove-lifecycle stale
  • Close this PR with/close
  • Offer to help out withIssue Triage

Please send feedback to sig-contributor-experience atkubernetes/community.

/lifecycle stale

@k8s-ci-robotk8s-ci-robot added the lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale. labelJun 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabianvffabianvfAwaiting requested review from fabianvf

@roycaihwroycaihwAwaiting requested review from roycaihw

Assignees

@yliaogyliaog

Labels
cncf-cla: yesIndicates the PR's author has signed the CNCF CLA.kind/bugCategorizes issue or PR as related to a bug.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.release-note-noneDenotes a PR that doesn't merit a release note.size/MDenotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

leaderelection do not stop leading properly
4 participants
@RaghavRoy145@k8s-ci-robot@k8s-triage-robot@yliaog

[8]ページ先頭

©2009-2025 Movatter.jp