changed leaderElectionConfig.getLeaseDuration to leaderElectionConfig… #7258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes [[#7160]
This pull request addresses a bug in the
LeaderElector
class, specifically in thecanBecomeLeader()
method. Previously, the method used the localleaderElectionConfig.getLeaseDuration()
value to determine if a lease had expired.This logic is flawed in scenarios where multiple leader election participants use different
leaseDuration
values. According to Kubernetes leader election semantics, clients should evaluate lease expiration based on the duration stored in the Lease object itself (leaseDurationSeconds
), not their own configuration.This discrepancy can lead to premature leadership takeovers and split-brain behavior. For example:
LE2
) runs withleaseDuration = 30s
,retryPeriod = 20s
.LE1
) runs withleaseDuration = 10s
,retryPeriod = 1s
.Even if
LE2
is correctly renewing the lease within its 30-second window,LE1
may incorrectly assume the lease has expired after 10 seconds, simply because it's using its own local config to calculate expiry.Fix
The method now uses the lease duration published in the lease record:
This ensures all clients interpret lease expiry based on the same source of truth — the current lease holder’s declared configuration — which aligns with how Kubernetes itself handles leader election.
Type of change
Checklist