Skip to content

Commit

Permalink
reconsider k8s version comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhasmitaSw committed Mar 15, 2022
1 parent 1d39b90 commit 969e6b1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func (v buildIdentifier) compare(o buildIdentifier) int {
}

type comparer struct {
buildTags bool
buildTags bool
withoutPreReleases bool
}

// CompareOption is a configuration option for Compare.
Expand All @@ -201,6 +202,12 @@ func WithBuildTags() CompareOption {
}
}

func WithoutPreReleases() CompareOption {
return func(c *comparer) {
c.withoutPreReleases = true
}
}

// 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.
Expand All @@ -212,6 +219,11 @@ func Compare(a, b semver.Version, options ...CompareOption) int {
o(c)
}

if c.withoutPreReleases {
a.Pre = nil
b.Pre = nil
}

if c.buildTags {
if comp := a.Compare(b); comp != 0 {
return comp
Expand Down

0 comments on commit 969e6b1

Please sign in to comment.