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

lets controllerManager.start() return instead of blocking #163

Merged
merged 1 commit into from
Oct 19, 2018

Conversation

mhrivnak
Copy link
Contributor

It always gets called as a goroutine, so nothing expects it to block. This
change slightly simplifies the code and lets the goroutine die instead of
keeping it around forever.

It always gets called as a goroutine, so nothing expects it to block. This
change slightly simplifies the code and lets the goroutine die instead of
keeping it around forever.
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 27, 2018
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 27, 2018
@mhrivnak
Copy link
Contributor Author

The diff looks more complex than it is. It just:

  1. removes the select from the bottom
  2. removes the inner func() block

Everything else is untouched except moving the indentation left.

When viewing it, if you click "Diff settings" and select "Hide whitespace changes", you'll see there's not much to it.

@droot
Copy link
Contributor

droot commented Oct 18, 2018

Looks good to me. Would like @JoelSpeed to take a look just to ensure this change plays nicely with the leaderElection code that we have in manager.Start().

@droot
Copy link
Contributor

droot commented Oct 19, 2018

Another thing I noticed that while using leader election, leaderElector passes its own stop channel to cm.start, so not sure if that leads to unexpected behavior. Also, the code for leader election in cm.Start sort of looks complex with multiple go routines and select blocks. /cc @JoelSpeed @mhrivnak @DirectXMan12

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

LGTM

Would like @JoelSpeed to take a look just to ensure this change plays nicely with the leaderElection code that we have in manager.Start()

This change shouldn't affect the behaviour of leader election in either client-go 8 or 9 (checking for futures sake). In both the OnStartedLeading is just started in a go-routine and the code doesn't care whether it blocks or not.

Another thing I noticed that while using leader election, leaderElector passes its own stop channel to cm.start, so not sure if that leads to unexpected behavior.

I don't think this does. When the leader elector loses leader it closes the channel and sends an error which in turn causes cm.Start to return the error, exiting the controller. If stop passed to cm.Start is closed then the function returns as well in theory closing the controller, we don't at this point then close the leader electors stop channel which I guess could cause problems, this could be avoided with a little refactor though. Want me to do that and make sure we ignore the leader elector's stop channel?

Also, the code for leader election in cm.Start sort of looks complex with multiple go routines and select blocks.

Yeah it's not pretty, could probably be made a lot nicer if I'd just used an else for the leader elector stuff, I'll raise a PR once to tidy it up a bit

@droot
Copy link
Contributor

droot commented Oct 19, 2018

I don't think this does. When the leader elector loses leader it closes the channel and sends an error which in turn causes cm.Start to return the error, exiting the controller. If stop passed to cm.Start is closed then the function returns as well in theory closing the controller, we don't at this point then close the leader electors stop channel which I guess could cause problems, this could be avoided with a little refactor though. Want me to do that and make sure we ignore the leader elector's stop channel?

Took a quick look a the leader elector lib, ignoring the leader elector's stop channel is fine as long as we exit when we stop leading (which we do as you explained above). I saw you made another PR, will take a look.

@droot droot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 19, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: mhrivnak

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 merged commit 605dc32 into kubernetes-sigs:master Oct 19, 2018
@mhrivnak mhrivnak deleted the let-start-return branch October 23, 2018 18:32
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
lets controllerManager.start() return instead of blocking
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Enhancement on sample projects for validation annotation
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants