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

replace TrimRight with TrimSuffix #8041

Merged
merged 1 commit into from
Dec 28, 2019
Merged

replace TrimRight with TrimSuffix #8041

merged 1 commit into from
Dec 28, 2019

Conversation

tanjunchen
Copy link
Member

In string based trim scenarios,we shall always use string based TrimPrefix/TrimSuffix instead of char based TrimLeft/TrimRight.
See the diff here: https://play.golang.org/p/S7cBaoIxPQy

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 4, 2019
@tanjunchen
Copy link
Member Author

/assign @chrisz100

@tanjunchen
Copy link
Member Author

/test pull-kops-e2e-kubernetes-aws

@tanjunchen
Copy link
Member Author

/cc @justinsb

@tanjunchen
Copy link
Member Author

/cc @rifelpet

@@ -160,7 +160,7 @@ func (a *AssetBuilder) RemapImage(image string) (string, error) {
}

if a.AssetsLocation != nil && a.AssetsLocation.ContainerProxy != nil {
containerProxy := strings.TrimRight(*a.AssetsLocation.ContainerProxy, "/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a safe change to make.

If I understand the differences correctly, this would mean that if a ContainerProxy contained a path after the host like proxy.example.com/path/, the old behavior would trim it down to proxy.example.com but the new behavior will trim it down to proxy.example.com/path. I don't know if having a path in ContainerProxy is valid, but if it is this would break existing behavior. Do we know if its valid or not?

Copy link
Member Author

@tanjunchen tanjunchen Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @justinsb
some works need to to check this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, with a single character in the second arg, TrimRight will remove multiple occurrences, whereas TrimSuffix will only remove one. So I think TrimRight is actually probably more correct here (just in case ContainerProxy ends with e.g. //), but I don't think it's likely to be a significant issue either way.

Is there a particular reason to make the change, @tanjunchen ? I agree we haven't been consistent, but I'm not sure which is right. Maybe we need a helper function that we use for all these url-style joins.

Copy link
Member Author

@tanjunchen tanjunchen Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rifelpet @justinsb Thanks your review.
Yes, i think it's likely to be a significant issue either way too.
I just found that only strings.TrimRight is used here in the kops project, and strings.TrimSuffix is used everywhere else.
The Only one strings.TrimRight in kops here.
Golang officially recommends this strings.TrimSuffix.

@k8s-ci-robot
Copy link
Contributor

@tanjunchen: GitHub didn't allow me to request PR reviews from the following users: for, decide.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @justinsb for decide
some works need to to check this change.

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.

@tanjunchen tanjunchen changed the title simplify code and replace TrimRight with TrimSuffix replace TrimRight with TrimSuffix Dec 16, 2019
@johngmyers
Copy link
Member

/test pull-kops-verify-staticcheck

@tanjunchen
Copy link
Member Author

/cc @justinsb maybe i need to make more convey about it

@k8s-ci-robot
Copy link
Contributor

@tanjunchen: GitHub didn't allow me to request PR reviews from the following users: need, convey, make, more, it, maybe, i, to.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @justinsb maybe i need to make more convey about it

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.

@justinsb
Copy link
Member

Let's merge it, but not cherry-pick it back unless there's a reason to... I'm pretty sure we meant TrimSuffix anyway!

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 28, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, tanjunchen

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 28, 2019
@johngmyers
Copy link
Member

/test pull-kops-e2e-kubernetes-aws

@k8s-ci-robot k8s-ci-robot merged commit b6be949 into kubernetes:master Dec 28, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants