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 847c0e7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 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,17 +202,29 @@ 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.
// Example: using the WithBuildTags() option modifies the compare logic to also
// consider build tags when comparing versions.
func Compare(a, b semver.Version, options ...CompareOption) int {

c := &comparer{}
for _, o := range options {
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 847c0e7

Please sign in to comment.