-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: localize absolute paths #5294
feat: localize absolute paths #5294
Conversation
Welcome @typeid! |
Hi @typeid. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
5c3befe
to
8762415
Compare
@rayandas Could you give this PR a review? |
@natasha41575 Sure. |
8762415
to
e3e4f87
Compare
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.
Hi there, @typeid!
Left some comments here. It seems this branch also needs to be rebased.
e3e4f87
to
3ec212e
Compare
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.
/lgtm
Sorry for the delay. /lgtm for me as well. Thank you! |
Thanks for your contribution! We'll try to get an approver to look at this in the next week or so. |
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.
@typeid Thank you for contributing to localize
! I think the core logic is there, we just need to scope down the PR and add tests. I can re-review after you've addressed the below comments.
api/internal/localizer/locloader.go
Outdated
if filepath.IsAbs(path) { | ||
return nil, errors.Errorf("absolute paths not yet supported in alpha: file path %q is absolute", path) | ||
if !strings.HasPrefix(path, ll.Root()) { | ||
return nil, fmt.Errorf("referenced absolute path '%s' in your Kustomization file is not in the same tree as '%s'", path, ll.Root()) | ||
} | ||
|
||
// Convert absolute path to relative path for unified handling | ||
path, err = filepath.Rel(ll.Root(), path) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not convert absolute path '%s' to relative path of root", path) | ||
} | ||
} |
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 only need to remove the previous check and ensuing error return.
Do we need this extra code segment? From what I see of your change in cleanFilePath
, you already handle passing in an absolute path, so we don't need to find the relative path in this code segment? Please correct me where I err.
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.
You're correct. I removed this redundant segment.
I had initially added the handling for absolute paths in Load
only, but cleanFilePath
is also called outside of it, so it broke as it couldn't handle absolute paths. Then I ended up handling it twice instead of centralizing it into just cleanFilePath
.
Also, I now see that the sanity checking of whether a file is inside of the root is already done in FileLoader.Load()
, which made most of previous my implementation redundant.
api/internal/localizer/util.go
Outdated
@@ -114,7 +114,11 @@ func hasRef(repoURL string) bool { | |||
|
|||
// cleanFilePath returns file cleaned, where file is a relative path to root on fSys | |||
func cleanFilePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string { |
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 PR currently writes a localized relative path in-place of the original absolute path in the localized copy. I'm down to keep this behavior, as opposed to preserving the absolute vs. relative nature of file paths, but can we upload a documentation PR to https://github.com/kubernetes-sigs/cli-experimental describing this behavior? We can also announce there the ability to localize absolute paths! We won't merge it until this one goes in.
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.
Makes sense, I'll look into that repo, open a PR and link it here once it's ready.
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.
kubernetes-sigs/cli-experimental#367 Let me know if this is enough or if it needs a bigger mention. I wasn't sure how to "version" the mention of the alpha command not handling absolute paths.
This PR has multiple commits, and the default merge method is: merge. 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. |
6e7113c
to
141a7ea
Compare
141a7ea
to
7b1eaf1
Compare
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale
/auto-cc
|
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.
Thank you for your contribution, @typeid! 😃
/lgtm
/cc @varshaprasad96
for maintainer review
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 changes look good to me. Thanks for the contribution @typeid!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: typeid, varshaprasad96 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 |
Attempts to fix #5275.
This PR adds handling of absolute paths to
kustomize localize
. To enable this, it converts the absolute paths to relative paths, keeping the rest of the processing chain intact.Please let me know if anything's missing (e.g. documentation), or if this is going in the wrong direction. It's my first contribution here :)