kube::core

Enum Version

Source
pub enum Version {
    Stable(u32),
    Beta(u32, Option<u32>),
    Alpha(u32, Option<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(u32, Option<u32>)

A beta release for a specific major version

Always considered higher priority than an alpha release.

§

Alpha(u32, Option<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§

Source§

impl Version

Source

pub fn parse(v: &str) -> Version

An infallble parse of a Kubernetes version string

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

impl Version

Source

pub fn priority(&self) -> impl Ord

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.

Source

pub fn generation(&self) -> impl Ord

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§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Version

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl FromStr for Version

An infallible FromStr implementation for more generic users

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Version, <Version as FromStr>::Err>

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

impl PartialEq for Version

Source§

fn eq(&self, other: &Version) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Version

Source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T