✨ added per controller leader election#444
✨ added per controller leader election#444GrigoriyMikhalkin wants to merge 2 commits intokubernetes-sigs:masterfrom
Conversation
|
/assign @droot |
mengqiy
left a comment
There was a problem hiding this comment.
We should add some validation to check if there are 2 different controller or manager using the same LE namespace and ID when starting the manager.
We may need to add a new method in the controller interface to get the LE config.
pkg/controller/controller.go
Outdated
|
|
||
| const ( | ||
| // Values taken from: https://github.com/kubernetes/apiserver/blob/master/pkg/apis/config/v1alpha1/defaults.go | ||
| defaultLeaseDuration = 15 * time.Second |
There was a problem hiding this comment.
These are shared bits between controller and manager packages and they can potentially moved to sigs.k8s.io/controller-runtime/pkg/leaderelection/internal.
@mengqiy You mean, check duplicate LE lock names used by manager and controllers that it manages? Or you mean totally unrelated managers and controllers? If later, i'm not sure how we can check that LE lock is created by different controller or manager. |
I mean the former. |
DirectXMan12
left a comment
There was a problem hiding this comment.
this all functions somewhat awkwardly with the "needs leader election" logic we've just implemented. I think what we really want to do is let things that request leader election (via the interface) return an "id suffix", then have the manager take care of launching the leader election.
|
that would also allow the manager to check for duplicate ids within a given manager |
|
@mengqiy @DirectXMan12 Completely rewrote code. Added new runnable interface(called it |
DirectXMan12
left a comment
There was a problem hiding this comment.
we already have the LeaderElectionRunnable interface, we should be able to use that.
@DirectXMan12 |
Correct -- "run before" is equivalent to "don't need leader election". We could actually just have
We're doing breaking changes this release anyway, but we could still have the default be to run under some standard leader election ID from the manager. |
2a0249f to
62aa08d
Compare
DirectXMan12
left a comment
There was a problem hiding this comment.
I think this is going in the right direction, but I think you need to pull out the global leader lock, which isn't serving any purpose anymore.
pkg/manager/internal.go
Outdated
| if resourceLock := cm.resourceLocksMap[cm.leaderElectionID]; resourceLock != nil { | ||
| err := cm.startLeaderElection(cm.leaderElectionID, leaderelection.LeaderCallbacks{ | ||
| OnStartedLeading: func(_ context.Context) { | ||
| cm.startLeaderElectionRunnables() |
There was a problem hiding this comment.
I don't think we need this double-leader election here -- in fact, it kinda defeats the purpose of per-controller leader election.
There was a problem hiding this comment.
Really, you want to try to start all of the locks independently.
pkg/manager/internal.go
Outdated
|
|
||
| // Check that leader election ID is unique | ||
| if _, exists := cm.resourceLocksMap[leID]; exists { | ||
| cm.errChan <- errors.New("LeaderElectionID must be unique") |
There was a problem hiding this comment.
that's not entirely true -- a group of controllers could choose to run under the same leader election
There was a problem hiding this comment.
(which might make sense if they needed the same resources, etc.
b490d36 to
8dfd21a
Compare
|
Updated. Now there's no global leader lock. But i use same |
8dfd21a to
a23fe42
Compare
How to handle LE namespace is debatable. Using the same @DirectXMan12 WDYT? |
|
Outcome of the f2f at kubecon was to support this, but default to manager's LE ID. We need to rebase this and make sure that's the state it's in. I'll take a poke at it. |
|
@GrigoriyMikhalkin are you still interested in working on this change? |
Yes. I'm gonna update this PR this weekend. |
|
Thank you! |
@DirectXMan12 So, by default, we want to make leader election for controllers? |
b2a1572 to
3dfb42d
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GrigoriyMikhalkin The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Basically, by default, keep the current behavior unless explicitly overridden by the controller. |
|
Updated PR. Now @DirectXMan12, @vincepri please review |
f3c711c to
0a1076a
Compare
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
@GrigoriyMikhalkin: PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
Planning to fix conflicts this weekend. Is there still plans to merge this? |
| // e.g. controllers need to be run in leader election mode, while webhook server doesn't. | ||
| NeedLeaderElection() bool | ||
| // GetLeaderElectionMode returns leader election mode in which Runnable needs to be run. | ||
| GetLeaderElectionMode() leaderelection.Mode |
There was a problem hiding this comment.
We can not do this. This will break all existing LeaderElection runnables in a way that they won't work anymore but without throwing any kind of compile error.
The current interface must stay as it is and remain having the same result as it has today. We can probably add a new interface and check for both.
|
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
@fejta-bot: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Attempt to solve #364