Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

yastij
Copy link
Member

@yastij yastij commented Jul 12, 2019

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

@k8s-ci-robot
Copy link
Contributor

Welcome @yastij!

It looks like this is your first PR to kubernetes/utils 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/utils has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 12, 2019
@yastij
Copy link
Member Author

yastij commented Jul 12, 2019

/assign @dims

@andrewsykim
Copy link
Member

/assign @lavalamp

Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yastij
To complete the pull request process, please assign dims
You can assign the PR to them by writing /assign @dims in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yastij
Copy link
Member Author

yastij commented Jul 12, 2019

build fails because of some lint errors, but I wanted to kick discussions with this PR

@dims
Copy link
Member

dims commented Jul 12, 2019

/assign @thockin

@dims
Copy link
Member

dims commented Jul 12, 2019

yea, ignore the lint errors. someone is working on it.

Copy link
Member

@thockin thockin left a 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.
Copy link
Member

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.
Copy link
Member

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 ""
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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).

https://play.golang.org/p/aDDvEZZ3aqX

}

// WithMajor returns copy of the version object with requested major number
func (v *Version) WithMajor(major uint) *Version {
Copy link
Member

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))
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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]+)*)(.*)*$`)
Copy link
Member

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").
Copy link
Member

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?

@danwinship
Copy link
Contributor

danwinship commented Jul 15, 2019

Don't we have like 4 semver libs in vendor/... already? Why do we have our own?

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?

@dims dims removed their assignment Jul 15, 2019
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 13, 2019
@yastij
Copy link
Member Author

yastij commented Oct 14, 2019

/close

@k8s-ci-robot
Copy link
Contributor

@yastij: Closed this PR.

In response to this:

/close

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.

@lavalamp
Copy link
Member

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. :) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants