Skip to content

Conversation

@lentzi90
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sbueringer for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the do-not-merge/needs-area PR is missing an area label label Oct 20, 2025
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 20, 2025
@lentzi90 lentzi90 force-pushed the lentzi90/ssa-cache-after-apply branch from 5e9c698 to 83a129c Compare October 23, 2025 07:21
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 23, 2025
@lentzi90 lentzi90 force-pushed the lentzi90/ssa-cache-after-apply branch from 83a129c to 3f0d275 Compare October 23, 2025 07:24
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 23, 2025
@lentzi90 lentzi90 changed the title 🌱 WIP: Add items to cache immediately after apply 🌱 Add items to cache immediately after apply Oct 23, 2025
@sbueringer sbueringer added the area/util Issues or PRs related to utils label Oct 23, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-area PR is missing an area label label Oct 23, 2025
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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)

Copy link
Contributor Author

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!

Copy link
Contributor Author

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...

Copy link
Member

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]>
@lentzi90 lentzi90 force-pushed the lentzi90/ssa-cache-after-apply branch from 3f0d275 to 2355648 Compare October 23, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/util Issues or PRs related to utils cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

3 participants