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

operator, hive, k8s: don't call workerpool.New from hive constructors #24419

Merged
merged 2 commits into from Mar 17, 2023

Conversation

tklauser
Copy link
Member

workerpool.New spawns a goroutine [1]. Per the hive guidelines [2], spawning of goroutines must not be performed from constructors, but rather via the Start hook. Fix three occurrences of this anti-pattern. See commits for details.

[1] https://github.com/cilium/workerpool/blob/054fdc524a07dfe6cc4123aba9bd76186605d960/workerpool.go#L68
[2] https://docs.cilium.io/en/latest/contributing/development/hive/#guidelines

@tklauser tklauser added the release-note/misc This PR makes changes that have no direct user impact. label Mar 17, 2023
@tklauser tklauser requested review from a team as code owners March 17, 2023 00:03
@tklauser tklauser requested review from squeed and joamaki March 17, 2023 00:03
@tklauser tklauser marked this pull request as draft March 17, 2023 07:43
workerpool.New spawns a goroutine [1]. Per the hive guidelines [2],
spawning of goroutines must not be performed from constructors, but
rather via the Start hook. Fix an occurrence of this anti-pattern in the
operator's identity GC constructor.

Also add a missing goleak check to TestIdentitiesGC so spawning of
goroutines in the constructor will be detected in the future.

[1] https://github.com/cilium/workerpool/blob/054fdc524a07dfe6cc4123aba9bd76186605d960/workerpool.go#L68
[2] https://docs.cilium.io/en/latest/contributing/development/hive/#guidelines

Fixes: b115951 ("operator: Refactor cilium identities GC to a cell")
Signed-off-by: Tobias Klauser <tobias@cilium.io>
workerpool.New spawns a goroutine [1]. Per the hive guidelines [2],
spawning of goroutines must not be performed from constructors, but
rather via the Start hook. Fix two occurrences of this anti-pattern
in hive examples.

[1] https://github.com/cilium/workerpool/blob/054fdc524a07dfe6cc4123aba9bd76186605d960/workerpool.go#L68
[2] https://docs.cilium.io/en/latest/contributing/development/hive/#guidelines

Signed-off-by: Tobias Klauser <tobias@cilium.io>
@tklauser tklauser force-pushed the pr/tklauser/hive-workerpool-new-onstart branch from fc9e4c2 to c93a471 Compare March 17, 2023 08:56
@tklauser tklauser marked this pull request as ready for review March 17, 2023 08:59
@tklauser
Copy link
Member Author

/test

Copy link
Contributor

@joamaki joamaki left a comment

Choose a reason for hiding this comment

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

Awesome thanks! Looks like it'd be good to extend operator/cmd/root_test.go with the goleak check the same way as in daemon/cmd/cells_test.go. Would you mind seeing if it'd be trivial to add it?

@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. labels Mar 17, 2023
@borkmann borkmann merged commit 9d4c226 into master Mar 17, 2023
41 checks passed
@borkmann borkmann deleted the pr/tklauser/hive-workerpool-new-onstart branch March 17, 2023 13:51
tklauser added a commit that referenced this pull request Mar 17, 2023
Add a goleak check the same way as in the daemon's TestAgentCell.

Reference: #24419 (review)
Suggested-by: Jussi Maki <jussi@isovalent.com>
Signed-off-by: Tobias Klauser <tobias@cilium.io>
@tklauser
Copy link
Member Author

Awesome thanks! Looks like it'd be good to extend operator/cmd/root_test.go with the goleak check the same way as in daemon/cmd/cells_test.go. Would you mind seeing if it'd be trivial to add it?

Sure, it was trivial to add. I've opened #24431 doing that.

tklauser added a commit that referenced this pull request Mar 21, 2023
Add a goleak check the same way as in the daemon's TestAgentCell.

Reference: #24419 (review)
Suggested-by: Jussi Maki <jussi@isovalent.com>
Signed-off-by: Tobias Klauser <tobias@cilium.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants