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

🐛 fix runnable run twice issue #487

Merged
merged 1 commit into from
Jun 28, 2019

Conversation

adohe-zz
Copy link

@adohe-zz adohe-zz commented Jun 12, 2019

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 12, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 12, 2019
Copy link
Contributor

@abursavich abursavich 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 the PR!

@@ -347,6 +352,7 @@ func (cm *controllerManager) startLeaderElection() (err error) {
RetryPeriod: cm.retryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(_ context.Context) {
cm.isLeader = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting isLeader needs to be protected by the mutex. I might suggest moving it into startLeaderElectionRunnables and changing its name to something like startedLeader?

Copy link
Author

Choose a reason for hiding this comment

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

yeap, that makes more sense. 👍

cm.nonLeaderElectionRunnables = append(cm.nonLeaderElectionRunnables, r)
} else {
shouldStart = cm.started && (cm.isLeader || cm.resourceLock == nil)
Copy link
Contributor

@abursavich abursavich Jun 12, 2019

Choose a reason for hiding this comment

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

If you take the suggestion from the other comment, this could be simplified to shouldStart = cm.startedLeader.

@adohe-zz adohe-zz force-pushed the fix_runnable_twice branch from 5e3d91f to e63210a Compare June 13, 2019 03:57
@DirectXMan12
Copy link
Contributor

fyi #444

@abursavich
Copy link
Contributor

abursavich commented Jun 14, 2019

The code looks good to me, but it would be nice to see the tests pass -- even though that failure doesn't look like your fault.

@abursavich
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@abursavich: changing LGTM is restricted to assignees, and only kubernetes-sigs/controller-runtime repo collaborators may be assigned issues.

In response to this:

/lgtm

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.

@adohe-zz
Copy link
Author

@DirectXMan12 kind ping~

@adohe-zz
Copy link
Author

@mengqiy @DirectXMan12 the CI is happy, kind ping~

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 28, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adohe, DirectXMan12

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

The pull request process is described here

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-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 28, 2019
@k8s-ci-robot k8s-ci-robot merged commit 28262f4 into kubernetes-sigs:master Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runnable added after manager started skips leader election and may run twice
5 participants