k8s v0.5.2 K8s.Version

Kubernetes API Versioning

Link to this section Summary

Functions

Returns only alpha versions

Returns only beta versions

Retuns all non-stable versions

Parses a Kubernetes API version into a K8s.Version struct

Returns the recommended version from a list of versions.

Returns only stable versions

Sorts a list of K8s.Versions

Returns only stable versions

Link to this section Types

Link to this type

t()

t() :: %K8s.Version{major: pos_integer(), minor: binary(), patch: pos_integer()}

Link to this section Functions

Link to this function

alpha(versions)

alpha([binary()]) :: [t()]

Returns only alpha versions

Examples

iex> K8s.Version.alpha(["v1alpha1", "v1", "v2beta1"])
[%K8s.Version{major: 1, minor: "alpha", patch: 1}]
Link to this function

beta(versions)

beta([binary()]) :: [t()]

Returns only beta versions

Examples

iex> K8s.Version.beta(["v1alpha1", "v1", "v2beta1"])
[%K8s.Version{major: 2, minor: "beta", patch: 1}]
Link to this function

edge(versions)

edge([binary()]) :: [t()]

Retuns all non-stable versions

Examples

iex> K8s.Version.edge(["v1alpha1", "v1", "v2beta1"])
[%K8s.Version{major: 1, minor: "alpha", patch: 1}, %K8s.Version{major: 2, minor: "beta", patch: 1}]
Link to this function

parse(version)

parse(binary()) :: t()

Parses a Kubernetes API version into a K8s.Version struct

Examples

iex> K8s.Version.parse("v1")
%K8s.Version{major: 1, minor: "stable", patch: nil}

iex> K8s.Version.parse("v1beta2")
%K8s.Version{major: 1, minor: "beta", patch: 2}

iex> K8s.Version.parse("v1alpha1")
%K8s.Version{major: 1, minor: "alpha", patch: 1}
Link to this function

recommended(versions)

recommended([binary()]) :: binary()

Returns the recommended version from a list of versions.

It will return the most stable version if any, otherwise the newest "edge" version.

Examples

iex> K8s.Version.recommended(["v1beta1", "v1", "v2"])
"v2"

iex> K8s.Version.recommended(["v1beta1", "v1"])
"v1"

iex> K8s.Version.recommended(["v1beta2", "v1beta1"])
"v1beta2"

iex> K8s.Version.recommended(["v1alpha1", "v1alpha2", "v1beta1"])
"v1beta1"
Link to this function

serialize(version)

serialize(t()) :: binary()

Returns only stable versions

Examples

iex> K8s.Version.serialize(%K8s.Version{major: 1, minor: "stable", patch: nil})
"v1"

iex> K8s.Version.serialize(%K8s.Version{major: 1, minor: "beta", patch: 1})
"v1beta1"

iex> K8s.Version.serialize(%K8s.Version{major: 1, minor: "alpha", patch: 1})
"v1alpha1"
Link to this function

sort(versions)

sort([t()]) :: [t()]

Sorts a list of K8s.Versions

Examples

iex> raw_versions = Enum.shuffle(["v1", "v2beta1", "v2", "v1alpha1", "v1alpha2"])
iex> versions = raw_versions |> Enum.map(&(K8s.Version.parse(&1)))
iex> sorted_versions = versions |> K8s.Version.sort()
iex> sorted_versions |> Enum.map(&(K8s.Version.serialize(&1)))
["v2", "v1", "v2beta1", "v1alpha2", "v1alpha1"]
Link to this function

stable(versions)

stable([binary()]) :: [t()]

Returns only stable versions

Examples

iex> K8s.Version.stable(["v1alpha1", "v1", "v2beta1"])
[%K8s.Version{major: 1, minor: "stable", patch: nil}]