New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add the version package to utils #98
Conversation
Welcome @yastij! |
/assign @dims |
/assign @lavalamp |
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
33e2355
to
9792021
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yastij The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
build fails because of some lint errors, but I wanted to kick discussions with this PR |
/assign @thockin |
yea, ignore the lint errors. someone is working on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have like 4 semver libs in vendor/... already? Why do we have our own?
// or more dot-separated numeric fields (the first of which can't have leading zeroes), | ||
// followed by arbitrary uninterpreted data (which need not be separated from the final | ||
// numeric field by punctuation). For convenience, leading and trailing whitespace is | ||
// ignored, and the version can be preceded by the letter "v". See also ParseSemantic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual examples of allowed values and disallowed values, highlighting the rules would be very helpful
// the "Semantic Versioning" specification (http://semver.org/) (although it ignores | ||
// leading and trailing whitespace, and allows the version to be preceded by "v"). For | ||
// version strings that are not guaranteed to obey the Semantic Versioning syntax, use | ||
// ParseGeneric. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual examples would be helpful
return v.components[2] | ||
} | ||
|
||
// BuildMetadata returns the build metadata, if v is a Semantic Version, or "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example of this
return v.components[1] | ||
} | ||
|
||
// Patch returns the patch release number if v is a Semantic Version, or 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a value is semver-like (triple) but not strictly semver - do we handle X.Y.Z%foo
} | ||
|
||
// Major returns the major release number | ||
func (v *Version) Major() uint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue none of these methods should be on pointers. The struct is value-like, we should treat it as such. Pointer methods require everyone use pointer (swill comment more below).
} | ||
|
||
// WithMajor returns copy of the version object with requested major number | ||
func (v *Version) WithMajor(major uint) *Version { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be returning pointers. It defeats some possible optimizations and forces everyone to use pointers.
https://play.golang.org/p/aDDvEZZ3aqX show how a helper function must return pointers to call these methods. If this is value-like, treat it like a value.
if i > 0 { | ||
buffer.WriteString(".") | ||
} | ||
buffer.WriteString(fmt.Sprintf("%d", comp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we sopecifically call components uint, but then you print it as an int here. Why don't we just store it as int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The you could use ItoA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just because it must be positive is NOT a good enough reason to use a uint.
|
||
var ( | ||
// versionMatchRE splits a version string into numeric and "extra" parts | ||
versionMatchRE = regexp.MustCompile(`^\s*v?([0-9]+(?:\.[0-9]+)*)(.*)*$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to allow parsing of numbers that could be bigger than a uint? Should we bound this to 10 characters (2^32) ?
// AtLeast tests if a version is at least equal to a given minimum version. If both | ||
// Versions are Semantic Versions, this will use the Semantic Version comparison | ||
// algorithm. Otherwise, it will compare only the numeric components, with non-present | ||
// components being considered "0" (ie, "1.4" is equal to "1.4.0"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples of normal and edge cases?
Well, this one is not just semver, which is why we have it (kubernetes/kubernetes#35436). But it's already in k/apimachinery. Why would it need to be moved to k/utils? |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/close |
@yastij: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
I think it'd be OK to move this (this is in apimachinery for lack of a better place; it's more build machinery, though, IMO), but it needs a name other than "version". Like, what's special about this version type? (Special attention to / opinions about all the stuff after the patch version number, it looks like.) Either way, it'd be nice to address @thockin's comments on the source package. :) :) |
Signed-off-by: Yassine TIJANI ytijani@vmware.com
This moves the version package to utils. it only depends on stdlib packages and is tested.
This would help unblock kubernetes/kubernetes#79526 specifically kubernetes/kubernetes#79526 (comment)
cc @andrewsykim @rosti @dims