Skip to content

feat: cache update on update control #2789

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

Closed
wants to merge 9 commits into from

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented May 9, 2025

No description provided.

csviri added 2 commits May 9, 2025 09:07
I think this never worked partially because the crd generator maven plugin
is not released into snapshot repo. For now I would just remove this.

Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
@openshift-ci openshift-ci bot requested review from metacosm and xstefank May 9, 2025 07:10
@csviri csviri changed the title cache update on update control feat: cache update on update control May 9, 2025
@csviri csviri marked this pull request as draft May 9, 2025 07:11
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 9, 2025
@csviri csviri linked an issue May 9, 2025 that may be closed by this pull request
csviri added 3 commits May 9, 2025 10:16
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
*
* @return if the framework should cache the updated resource for next reconciliation
*/
default boolean cacheUpdatedResourcesViaUpdateControl() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to have a different option for this? More precisely, wouldn't it make sense to activate automatic caching whenever parsing of the resource version is activated? I mean the name of the parse method already implies that it is used for caching.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not exactly, parsing resource version was done for now only in dependent resources.

I think this should be an opt-in feature since it does not strictly follows K8S API contract, so user should be aware. I would not turn it on by default for the low level API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also if there are some issues user can still turn it off.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that adding options for corner cases makes things a lot more complex to understand, especially when the setting only applies when some other setting is enabled. To me, all these options should really be hidden under a single one where everything that can be done by assuming the resource versions grow monotonically should be done automatically when parsing is activated.

Also, if there are potential issues, then we probably shouldn't have the features to start with. Either we can implement it correctly or we shouldn't provide the feature. That's something I actually dislike with the SSA support: it's not working in all cases and makes things more complex to the point that people might not want to use it or actually revert to using optimistic-looking based updates. This isn't great.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, the method name isn't correct as the setting impacts more than updates via UpdateControl, at least from what I can tell.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's something I actually dislike with the SSA support: it's not working in all cases and makes things more complex to the point that people might not want to use it or actually revert to using optimistic-looking based updates. This isn't great.

I don't see what SSA has to do with optimistic locking. OL can be turned on all update / patch types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, if there are potential issues, then we probably shouldn't have the features to start with. Either we can implement it correctly or we shouldn't provide the feature.

It's not about potential issues, I don't see any, but it is good to have a failsafe. Note that this what we have is again bending a bit the Kuberentes API contract. It is safe with ETCD at the backed, might be different for a non etc etc. For what we provide the alternative explicit cache.

* next reconciliation will receive the most up-to-date resource. This is a consequence of
* Informers design in the Operator pattern.
*
* <p>The framework can be smart about it and make such guarantees, but this can be done
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole paragraph is less explicit and clear that what it could be, imo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will take a look thx.

*/
default boolean parseResourceVersionsForEventFilteringAndCaching() {
return false;
}

/**
* If you update the primary resource from the reconciler with or without {@link
* io.javaoperatorsdk.operator.api.reconciler.UpdateControl} it is not guaranteed that for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't really make sense. What's the point of referring to UpdateControl if that can happen whether we use it or not?

*
* @return if the framework should cache the updated resource for next reconciliation
*/
default boolean cacheUpdatedResourcesViaUpdateControl() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that adding options for corner cases makes things a lot more complex to understand, especially when the setting only applies when some other setting is enabled. To me, all these options should really be hidden under a single one where everything that can be done by assuming the resource versions grow monotonically should be done automatically when parsing is activated.

Also, if there are potential issues, then we probably shouldn't have the features to start with. Either we can implement it correctly or we shouldn't provide the feature. That's something I actually dislike with the SSA support: it's not working in all cases and makes things more complex to the point that people might not want to use it or actually revert to using optimistic-looking based updates. This isn't great.

*
* @return if the framework should cache the updated resource for next reconciliation
*/
default boolean cacheUpdatedResourcesViaUpdateControl() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, the method name isn't correct as the setting impacts more than updates via UpdateControl, at least from what I can tell.

@csviri
Copy link
Collaborator Author

csviri commented May 12, 2025

@metacosm @xstefank we can discuss this also on tomorrow community meeting. @metacosm will take a look on javadocs, note that this is a Draft, actively working on it and might have significant changes.

csviri added 4 commits May 14, 2025 10:16
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
@csviri csviri marked this pull request as ready for review May 14, 2025 11:00
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 14, 2025
@openshift-ci openshift-ci bot requested a review from metacosm May 14, 2025 11:00
@csviri
Copy link
Collaborator Author

csviri commented May 14, 2025

@metacosm I added docs and refined the javadoc and naming, also based on our discussion yesterday.

However did not do any fundamental changes on logic, other than throw an exception if the parseResourceVersionsForEventFilteringAndCaching is set to false and withGuaranteeUpdatedPrimaryIsAvailableForNextReconciliation set to true we throw an exception. Please take a look also @xstefank.

If you find this too confusing, we could simply not support this in this way (let's discuss that) and we can close this PR.

I created an issue v6 (which I guess won't come this year), to remove the update/patch methods from UpdateControl in the future:
#2797
But that is something to discuss further.

@csviri
Copy link
Collaborator Author

csviri commented May 14, 2025

See this PR:
https://github.com/operator-framework/java-operator-sdk/pull/2799/files

It will provide also the lock version of of the updated resources described here:
#2798

That would be an other feature flag etc to support internally and since in the future we probably will leave this UpdateControl based approach will close this PR and just have these features supported by the PrimaryUpdateAndCacheUtils.

see also: #2797

@csviri csviri closed this May 14, 2025
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.

Automatically cache resource from UpdateControl patch responses
2 participants