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

feat: localize absolute paths #5294

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

typeid
Copy link
Contributor

@typeid typeid commented Aug 25, 2023

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 25, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @typeid!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. 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-sigs/kustomize 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
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 25, 2023
@typeid typeid force-pushed the localize_absolute_paths branch 4 times, most recently from 5c3befe to 8762415 Compare August 25, 2023 16:45
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 28, 2023
@natasha41575
Copy link
Contributor

@rayandas Could you give this PR a review?

@rayandas
Copy link
Member

@natasha41575 Sure.
/assign

api/loader/fileloader.go Outdated Show resolved Hide resolved
api/krusty/accumulation_test.go Outdated Show resolved Hide resolved
api/loader/fileloader_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2023
@natasha41575 natasha41575 assigned annasong20 and unassigned ezzoueidi and rayandas Oct 6, 2023
Copy link
Member

@stormqueen1990 stormqueen1990 left a 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.

api/internal/localizer/locloader.go Outdated Show resolved Hide resolved
api/loader/fileloader_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2023
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 9, 2023
@ezzoueidi
Copy link
Contributor

Sorry for the delay.

/lgtm for me as well. Thank you!

@natasha41575
Copy link
Contributor

Thanks for your contribution! We'll try to get an approver to look at this in the next week or so.

Copy link
Contributor

@annasong20 annasong20 left a 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/loader/fileloader.go Outdated Show resolved Hide resolved
api/internal/loader/fileloader_test.go Outdated Show resolved Hide resolved
api/krusty/accumulation_test.go Outdated Show resolved Hide resolved
Comment on lines 95 to 105
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)
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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/locloader_test.go Outdated Show resolved Hide resolved
api/internal/localizer/locloader_test.go Outdated Show resolved Hide resolved
api/internal/localizer/util.go Outdated Show resolved Hide resolved
api/internal/localizer/util.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

api/internal/localizer/util.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 26, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Feb 24, 2024
@stormqueen1990
Copy link
Member

stormqueen1990 commented Feb 24, 2024 via email

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 24, 2024
Copy link
Member

@stormqueen1990 stormqueen1990 left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 24, 2024
Copy link
Member

@varshaprasad96 varshaprasad96 left a 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

@k8s-ci-robot
Copy link
Contributor

[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 /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 Apr 30, 2024
@k8s-ci-robot k8s-ci-robot merged commit 49a645f into kubernetes-sigs:master Apr 30, 2024
9 checks passed
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

Localize absolute paths
9 participants