Documentation
¶
Overview ¶
Package version implements version handling.
Index ¶
- Variables
- func Compare(a, b semver.Version, options ...CompareOption) int
- func MajorMinorPatch(version semver.Version) semver.Version
- func ParseMajorMinorPatch(version string) (semver.Version, error)deprecated
- func ParseMajorMinorPatchTolerant(version string) (semver.Version, error)deprecated
- func ParseTolerantImageTag(version string) (semver.Version, error)
- type CompareOption
Constants ¶
This section is empty.
Variables ¶
var ( // KubeSemver is the regex for Kubernetes versions. It requires the "v" prefix. KubeSemver = regexp.MustCompile(`^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`) // KubeSemverTolerant is the regex for Kubernetes versions with an optional "v" prefix. KubeSemverTolerant = regexp.MustCompile(`^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`) )
Functions ¶
func Compare ¶ added in v0.99.99
func Compare(a, b semver.Version, options ...CompareOption) int
Compare 2 semver versions. Defaults to doing the standard semver comparison when no options are specified. The comparison logic can be modified by passing additional compare options. Example: using the WithBuildTags() option modifies the compare logic to also consider build tags when comparing versions.
func MajorMinorPatch ¶ added in v1.11.0
func MajorMinorPatch(version semver.Version) semver.Version
MajorMinorPatch returns a version that only has Major / Minor / Patch fields set.
func ParseMajorMinorPatch
deprecated
ParseMajorMinorPatch returns a semver.Version from the string provided by looking only at major.minor.patch and stripping everything else out. It requires the version to have a "v" prefix.
Deprecated: This function is deprecated and will be removed in an upcoming release of Cluster API. Please use semver.Parse instead.
func ParseMajorMinorPatchTolerant
deprecated
ParseMajorMinorPatchTolerant returns a semver.Version from the string provided by looking only at major.minor.patch and stripping everything else out. It does not require the version to have a "v" prefix.
Deprecated: This function is deprecated and will be removed in an upcoming release of Cluster API. Please use semver.ParseTolerant instead.
func ParseTolerantImageTag ¶ added in v1.11.0
ParseTolerantImageTag replaces all _ with + in version and then parses the version with semver.ParseTolerant. This allows to parse image tags which cannot contain +, so they use _ instead of +.
Types ¶
type CompareOption ¶ added in v0.99.99
type CompareOption func(*comparer)
CompareOption is a configuration option for Compare.
func WithBuildTags ¶ added in v0.99.99
func WithBuildTags() CompareOption
WithBuildTags modifies the version comparison to also consider build tags when comparing versions. Performs a standard version compare between a and b. If the versions are equal, build identifiers will be used to compare further; precedence for two build identifiers is determined by comparing each dot-separated identifier from left to right until a difference is found as follows: - Identifiers consisting of only digits are compared numerically. - Numeric identifiers always have lower precedence than non-numeric identifiers. - Identifiers with letters or hyphens are compared only for equality, otherwise, 2 is returned given that it is not possible to identify if lower or greater (non-numeric identifiers could be random build identifiers).
-1 == a is less than b. 0 == a is equal to b. 1 == a is greater than b. 2 == v is different than o (it is not possible to identify if lower or greater).
func WithoutPreReleases ¶ added in v1.2.0
func WithoutPreReleases() CompareOption
WithoutPreReleases modifies the version comparison to not consider pre-releases when comparing versions.