-
Couldn't load subscription status.
- Fork 1.4k
🌱 Add items to cache immediately after apply #12877
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
base: main
Are you sure you want to change the base?
🌱 Add items to cache immediately after apply #12877
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5e9c698 to
83a129c
Compare
83a129c to
3f0d275
Compare
internal/util/ssa/patch.go
Outdated
| options.Cache.Add(requestIdentifier) | ||
| // If the object changed, we need to recompute the request identifier before caching. | ||
| if options.Original.GetResourceVersion() != modifiedUnstructured.GetResourceVersion() { | ||
| requestIdentifier, err = ComputeRequestIdentifier(c.Scheme(), modifiedUnstructuredBeforeApply, modifiedUnstructured) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| requestIdentifier, err = ComputeRequestIdentifier(c.Scheme(), modifiedUnstructuredBeforeApply, modifiedUnstructured) | |
| requestIdentifier, err = ComputeRequestIdentifier(c.Scheme(), modifiedUnstructured, modifiedUnstructuredBeforeApply) |
We have to use the resourceVersion from modifiedUnstructured (it contains at this point the response from the server after Apply including the latest resourceVersion) and the hash from modifiedUnstructuredBeforeApply because this is what the next reconcile will pass into the func. modifiedUnstructured will contain all fields of the resource, not just the ones that our client wants to set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check why the unit test didn't detect that this didn't cache correctly and see if that can be improved that it would have detected it
(I'll skip review of the unit test for this review as I"m not sure how much it will change)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll check!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I got confused because of the argument names in ComputeRequestIdentifier. It takes in original and modified, so I wanted to put the "before apply" as original. 😵 .
Anyway, this makes me wonder how useful the test really is. I just did the same there to calculate the request identifier. At least the test will catch if the code is changed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, let's improve as suggested in the Slack thread.
The names are indeed not great. Not sure if I have ideas for just better names, I would have some for also changing the type of the first parameter but that might have some larger impact on other usages of this util
(so probably let's keep the ComputeRequestIdentifier func as is for now)
This improves the SSA helper by avoding a second no-op patch just to add items to the cache. Instead we calculate the new request identifier and add to the cache directly. Signed-off-by: Lennart Jern <[email protected]>
3f0d275 to
2355648
Compare
What this PR does / why we need it:
Add items to cache immediately after apply to avoid extra no-op patch just for caching.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Part of #12291