-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Export Version priority parser with Ord impls in kube_core #764
Conversation
kube-core/src/version.rs
Outdated
@@ -137,7 +207,7 @@ mod tests { | |||
Version::Stable(2), | |||
Version::Beta(2, Some(3)), | |||
]; | |||
vers.sort(); | |||
vers.sort_by_cached_key(|x| Reverse(x.clone())); |
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.
This is the only semi-annoying consequence of the reversal here.
A clone is forced on us from rust-lang/rust#34162 unless we use the manual cmp
calll reversed ourselves.
I think this is ok, the usage in kube_client does not need to clone because the Version parsing IS the temporary step, and the test here is probably less realistic of a use-case)
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.
Ord
has a blanket impl that &T: Ord where T: Ord
, so I think this should line up correctly. Or do the lifetimes not match properly?
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.
End up getting this :/
error: lifetime may not live long enough
--> kube-core/src/version.rs:208:37
|
208 | vers.sort_by_cached_key(|x| Reverse(x));
| -- ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is Reverse<&'2 version::Version>
| has type `&'1 version::Version`
This comment has been minimized.
This comment has been minimized.
kube-core/src/version.rs
Outdated
Alpha(u32, Option<u32>), | ||
// CRDs and APIServices can use arbitrary strings as versions. | ||
/// An non-conformant api string (sorted lexicographically) |
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.
This isn't really new, but this might be worth reconsidering before stabilizing. Keeping this "everything else" case means that anyone relying on it will silently be broken if we add new primary cases.
Instead, we might want to turn Nonconformant
into the error case on <Version as FromStr>
?
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.
According to Version Priority any non-conformant value is legal. I may want to set my CRD version to testing
and expect it to work with k8s. So failing the parser on that will make it unusable from kube
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.
To be clear: I am not saying that a non-conformant version is illegal, or that we should reject working with it. Rather, that we should treat it as an opaque String
in general, parse it into a Version
when needed (such as for comparisons), and accept that that parsing may fail (with reasonable fallback behaviour, as described in the PR body).
kube-core/src/version.rs
Outdated
@@ -137,7 +207,7 @@ mod tests { | |||
Version::Stable(2), | |||
Version::Beta(2, Some(3)), | |||
]; | |||
vers.sort(); | |||
vers.sort_by_cached_key(|x| Reverse(x.clone())); |
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.
Ord
has a blanket impl that &T: Ord where T: Ord
, so I think this should line up correctly. Or do the lifetimes not match properly?
doing the cleanup steps described to make this worthy of exporting. needed for kube-rs/kopium#23 Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
* Explicitly request which ordering to use Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se> * Add `Version::latest` that includes considers v2 > v2beta1 > v1 Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se> * Rename Version::latest_stable to priority Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se> * Also rename LatestStable accordingly Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
we had two orders ::latest and ::priority, but v.latest() was a ambiguous. v.latest could mean: - we are sorting by age (but that's not true) - we are sorting by latest version in semver semantics (true so think v.semantic() is slightly more clear. v2.semantic() > v1.semantic() feels a little easier to comprehend than v2.latest() > v1.latest() Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
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.
LGTM, just a few minor nits remaining
See kube-rs#764 (comment) Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
See #764 (comment) Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
Co-authored-by: Teo Klestrup Röijezon <teo.roijezon@stackable.de>
Thanks for all the diligent review here 👍 Happy to merge at this point. As a funny side-note about this naming: |
Co-authored-by: kazk <kazk.dev@gmail.com>
CI instability from github's side this morning. Either it's the cargo deny locking up in a docker run, or k3d failing to start the cluster, so guessing there are some temporary docker issues on some actions runners. In either case everything here has passed checks. Merging. |
needed for kube-rs/kopium#23
This does the self-comment cleanup steps described to make this worthy of exporting:
Also adds a small doctest for the thing, and an infallible
FromStr
impl (which may end up being useful to someone - maybe).