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

Allow GeneratingHandlers to skip Apply if resource version didn't change #341

Merged
merged 12 commits into from
Dec 22, 2023

Conversation

aruiz14
Copy link
Contributor

@aruiz14 aruiz14 commented Nov 23, 2023

Extends GeneratingHandlerOptions to allow a new UniqueApplyForResourceVersion, which will keep track of the latest resource version for each individual resource that was handled, avoiding subsequent calls to Apply if the first one was successful. The goal is to limit the number of Apply is called with the same inputs, reducing the computation costs. However, this means that handlers must be deterministic, in the sense that they must produce the same object list for the same input resource, hence this option must be carefully enabled on a case by case basis. It has no impact on other users if the option is not enabled.

We have successfully tested this feature on Fleet's Bundle and GitRepo generating handlers (see rancher/fleet#1964 for an example usage), while trying to mitigate the effect of over-firing handlers (we are also working towards the root cause of the over-firing, which may be partially caused by the use of Enqueue).

@aruiz14 aruiz14 marked this pull request as ready for review November 24, 2023 08:04
Copy link
Contributor

@rmweir rmweir left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@KevinJoiner KevinJoiner left a comment

Choose a reason for hiding this comment

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

Overall, this looks good. I don't love adding more code in generated templates, but this is a good approach to solving the problem.

Also, I didn't mark this but I would be forever grateful if you added function comments to GeneratingHandler since you are already in the package.

pkg/controller-gen/generators/type_go.go Outdated Show resolved Hide resolved
pkg/controller-gen/generators/type_go.go Outdated Show resolved Hide resolved
pkg/controller-gen/generators/type_go.go Outdated Show resolved Hide resolved
pkg/generic/generating_test.go Outdated Show resolved Hide resolved
@aruiz14 aruiz14 requested a review from KevinJoiner December 13, 2023 10:43
@aruiz14
Copy link
Contributor Author

aruiz14 commented Dec 15, 2023

Also, I didn't mark this but I would be forever grateful if you added function comments to GeneratingHandler since you are already in the package.

I'm sorry I missed this comment when I first addressed your feedback. It's done now, please take another look, thanks!

@cwayne18 cwayne18 merged commit f5d32fe into rancher:master Dec 22, 2023
1 check passed
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 3, 2024
…nge (rancher#341)

* Allow GeneratingHandlers to skip Apply if resource version didn't change

* Run go generate

* Add call count to FakeApply

* Add test for UniqueApplyForResourceVersion

* Simplify error handling

Co-authored-by: Kevin Joiner <[email protected]>

* Make generated code more readable

Co-authored-by: Kevin Joiner <[email protected]>

* Rename constant

* Rename seenResourceVersion to storeResourceVersion

* go generate

* Add comments to code generator

* Run go generate

* Upgrade golangci-lint GitHub action, since it always fails now

---------

Co-authored-by: Kevin Joiner <[email protected]>
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 5, 2024
…nge (rancher#341)

* Allow GeneratingHandlers to skip Apply if resource version didn't change

* Run go generate

* Add call count to FakeApply

* Add test for UniqueApplyForResourceVersion

* Simplify error handling

Co-authored-by: Kevin Joiner <[email protected]>

* Make generated code more readable

Co-authored-by: Kevin Joiner <[email protected]>

* Rename constant

* Rename seenResourceVersion to storeResourceVersion

* go generate

* Add comments to code generator

* Run go generate

* Upgrade golangci-lint GitHub action, since it always fails now

---------

Co-authored-by: Kevin Joiner <[email protected]>
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 9, 2024
…nge (rancher#341)

* Allow GeneratingHandlers to skip Apply if resource version didn't change

* Run go generate

* Add call count to FakeApply

* Add test for UniqueApplyForResourceVersion

* Simplify error handling

Co-authored-by: Kevin Joiner <[email protected]>

* Make generated code more readable

Co-authored-by: Kevin Joiner <[email protected]>

* Rename constant

* Rename seenResourceVersion to storeResourceVersion

* go generate

* Add comments to code generator

* Run go generate

* Upgrade golangci-lint GitHub action, since it always fails now

---------

Co-authored-by: Kevin Joiner <[email protected]>
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 10, 2024
…nge (rancher#341)

* Allow GeneratingHandlers to skip Apply if resource version didn't change

* Run go generate

* Add call count to FakeApply

* Add test for UniqueApplyForResourceVersion

* Simplify error handling

Co-authored-by: Kevin Joiner <[email protected]>

* Make generated code more readable

Co-authored-by: Kevin Joiner <[email protected]>

* Rename constant

* Rename seenResourceVersion to storeResourceVersion

* go generate

* Add comments to code generator

* Run go generate

* Upgrade golangci-lint GitHub action, since it always fails now

---------

Co-authored-by: Kevin Joiner <[email protected]>
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 10, 2024
…nge (rancher#341)

* Allow GeneratingHandlers to skip Apply if resource version didn't change

* Run go generate

* Add call count to FakeApply

* Add test for UniqueApplyForResourceVersion

* Simplify error handling

Co-authored-by: Kevin Joiner <[email protected]>

* Make generated code more readable

Co-authored-by: Kevin Joiner <[email protected]>

* Rename constant

* Rename seenResourceVersion to storeResourceVersion

* go generate

* Add comments to code generator

* Run go generate

* Upgrade golangci-lint GitHub action, since it always fails now

---------

Co-authored-by: Kevin Joiner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants