Skip to content

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Oct 10, 2025

based on: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/5504-comparable-resource-version#helper-function

This also seems to be significantly faster also in java, even in worst case scenario.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
@openshift-ci openshift-ci bot requested review from metacosm and xstefank October 10, 2025 11:40
@csviri csviri changed the base branch from main to next October 10, 2025 11:40
@csviri csviri changed the title comparator function Resource version comparison utility Oct 10, 2025
@csviri csviri requested a review from shawkins October 10, 2025 11:41
@csviri csviri linked an issue Oct 10, 2025 that may be closed by this pull request
@shawkins
Copy link
Collaborator

Should this include the numeric sanity checks as well?

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
@csviri
Copy link
Collaborator Author

csviri commented Oct 10, 2025

Should this include the numeric sanity checks as well?

added, it is not perfect this way, but I would say good enough, what do you think?

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
…tor/api/reconciler/PrimaryUpdateAndCacheUtils.java

Co-authored-by: Steven Hawkins <shawkins@redhat.com>
@csviri csviri requested a review from shawkins October 10, 2025 14:15
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
…tor/api/reconciler/PrimaryUpdateAndCacheUtils.java

Co-authored-by: Steven Hawkins <shawkins@redhat.com>
…tor/api/reconciler/PrimaryUpdateAndCacheUtils.java

Co-authored-by: Steven Hawkins <shawkins@redhat.com>
if (v2Length == 0) {
throw new IllegalStateException("Resource version (2) is empty");
}
var maxLength = Math.max(v1Length, v2Length);
Copy link
Collaborator Author

@csviri csviri Oct 10, 2025

Choose a reason for hiding this comment

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

Assuming we don't have leading zeros, would it make sense to compare the lenghts upfront?
In general there would be not a bug win for that, but might simplify things.
I'm pretty sure etcd does not generate versions with leading zeros

@shawkins

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

( I mean I could leave with that assumption :) )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Assuming we don't have leading zeros, would it make sense to compare the lenghts upfront?

That also short circuits the check for non-digit characters. So if you want to go with that approach, then just revert to the initial state of the pr - and consider putting the resource version validation elsewhere if you want a sanity check.

Copy link
Collaborator Author

@csviri csviri Oct 10, 2025

Choose a reason for hiding this comment

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

For now reverted for sake of simplicity / readability, but we can discuss on next community meeting, and maybe decide with others which one to take.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But added the validation you proposed

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's probably confusing to have the other sanity checks in there - I'd vote to either fully validate or not at all.

I would add that the performance difference between fully validating and partially validating should be minimal in the long run. As the api server is up longer, the larger resource versions will get, and the less likely it will be for there to be a difference in the length.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
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.

Comparable Resource Versions in Kubernetes

2 participants