pub enum Version {
    Stable(u32),
    Beta(u32Option<u32>),
    Alpha(u32Option<u32>),
    Nonconformant(String),
}
Expand description

Version parser for Kubernetes version patterns

This type implements two orderings for sorting by:

To get the api versions sorted by kubectl priority:

use kube_core::Version;
use std::cmp::Reverse; // for DESCENDING sort
let mut versions = vec![
    "v10beta3",
    "v2",
    "foo10",
    "v1",
    "v3beta1",
    "v11alpha2",
    "v11beta2",
    "v12alpha1",
    "foo1",
    "v10",
];
versions.sort_by_cached_key(|v| Reverse(Version::parse(v).priority()));
assert_eq!(versions, vec![
    "v10",
    "v2",
    "v1",
    "v11beta2",
    "v10beta3",
    "v3beta1",
    "v12alpha1",
    "v11alpha2",
    "foo1",
    "foo10",
]);

Variants

Stable(u32)

A major/GA release

Always considered higher priority than a beta release.

Beta(u32Option<u32>)

A beta release for a specific major version

Always considered higher priority than an alpha release.

Alpha(u32Option<u32>)

An alpha release for a specific major version

Always considered higher priority than a nonconformant version

Nonconformant(String)

An non-conformant api string

CRDs and APIServices can use arbitrary strings as versions.

Implementations

An infallble parse of a Kubernetes version string

use kube_core::Version;
assert_eq!(Version::parse("v10beta12"), Version::Beta(10, Some(12)));

An Ord for Version that orders by Kubernetes version priority

This order will favour stable versions over newer pre-releases and is used by kubectl.

For example:

assert!(Version::Stable(2).priority() > Version::Stable(1).priority());
assert!(Version::Stable(1).priority() > Version::Beta(1, None).priority());
assert!(Version::Stable(1).priority() > Version::Beta(2, None).priority());
assert!(Version::Stable(2).priority() > Version::Alpha(1, Some(2)).priority());
assert!(Version::Stable(1).priority() > Version::Alpha(2, Some(2)).priority());
assert!(Version::Beta(1, None).priority() > Version::Nonconformant("ver3".into()).priority());

Note that the type of release matters more than the version numbers: Stable(x) > Beta(y) > Alpha(z) > Nonconformant(w) for all x,y,z,w

Nonconformant versions are ordered alphabetically.

An Ord for Version that orders by version generation

This order will favour higher version numbers even if it’s a pre-release.

For example:

assert!(Version::Stable(2).generation() > Version::Stable(1).generation());
assert!(Version::Stable(1).generation() > Version::Beta(1, None).generation());
assert!(Version::Beta(2, None).generation() > Version::Stable(1).generation());
assert!(Version::Stable(2).generation() > Version::Alpha(1, Some(2)).generation());
assert!(Version::Alpha(2, Some(2)).generation() > Version::Stable(1).generation());
assert!(Version::Beta(1, None).generation() > Version::Nonconformant("ver3".into()).generation());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

An infallible FromStr implementation for more generic users

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more