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

LeaderElection leader transitions #4320

Closed
shawkins opened this issue Aug 5, 2022 · 2 comments · Fixed by #4322
Closed

LeaderElection leader transitions #4320

shawkins opened this issue Aug 5, 2022 · 2 comments · Fixed by #4322
Assignees
Labels
Milestone

Comments

@shawkins
Copy link
Contributor

shawkins commented Aug 5, 2022

LeaderTransitions is resetting on a change of leadership, and incrementing while holding the lock. I think this should instead be to increment on a change and to leave the value alone will renewing.

@shawkins shawkins added the bug label Aug 5, 2022
@shawkins shawkins added this to the 6.1.0 milestone Aug 5, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 8, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 8, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 8, 2022
@manusa
Copy link
Member

manusa commented Aug 9, 2022

The leader election record leaderTransitions field should only increment after a change of leadership.

Related client-go code in leaderelection.go:

	// 3. We're going to try to update. The leaderElectionRecord is set to it's default
	// here. Let's correct it before updating.
	if le.IsLeader() {
		leaderElectionRecord.AcquireTime = oldLeaderElectionRecord.AcquireTime
		leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions
	} else {
		leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions + 1
	}

The following code needs an update (+test):

final LeaderElectionRecord newLeaderElectionRecord = new LeaderElectionRecord(
lock.identity(),
leaderElectionConfig.getLeaseDuration(),
isLeader ? oldLeaderElectionRecord.getAcquireTime() : now,
now,
isLeader ? (oldLeaderElectionRecord.getLeaderTransitions() + 1) : 0);

@shawkins
Copy link
Contributor Author

shawkins commented Aug 9, 2022

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 9, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 10, 2022
@manusa manusa closed this as completed in 6d0aec7 Aug 10, 2022
@manusa manusa linked a pull request Aug 11, 2022 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants