-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Implement kustomize localize
localization layer
#4797
Conversation
@annasong20: 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. |
Hi @annasong20. 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. |
EDIT: moving previous PR description into this comment TL;DR The current implementation of kustomization field processing is more of a brute force approach. Feedback is welcome. To process the kustomization fields, I tried
is responsible for accepting a localizing function like These designs were abandoned because
============================================================================================ The purpose of this PR is for @natasha41575 to give high-level feedback. The PR is incomplete:
I will continue to update this PR and mark it "Ready for review" when finished. |
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 think the logic mostly looks good. I have a few questions, but I think this is headed in a great direction!
/ok-to-test |
41d0e23
to
7f1e996
Compare
I've completed the integration tests and refactored the code so that all checks should pass. I'll work on |
api/krusty/remotelocalizer_test.go
Outdated
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
) | ||
|
||
const simpleHTTPS = "https://github.com/kubernetes-sigs/kustomize//api/krusty/testdata/localize/simple" |
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.
Since #4783 has been merged, if you'd prefer, I believe I could replace these urls with local, file://
-prefixed urls? I'd have to look into it, but lmk. If I made this change, I'd add tests for parseDomain
.
ldr, err := ll.Loader.New(path) | ||
// timeout indicates path is a root, not a file | ||
if utils.IsErrTimeout(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.
Note to self: Add TODO statement to refactor once appropriate errors added to ifc.Loader
/label tide/merge-method-squash |
Updated PR with most plugin changes. I have yet to fix some lint errors. There are more |
TL;DR The functional logic in this PR is now complete, though test-writing, refactoring, etc. are still a WIP. I've added I've also exposed an entry point Next steps:
|
My major question about this PR is around the large amount of changes to builtin and plugin transformers. I think in general we need a progressive PR merge and release plan to make sure the minimum users are affected and relief the releasing burdens from the kustomize owners (e.g. if a single transformer has behavior shift, whether this is expected or not, it could break their productions). From the PR description itself, it seems not necessary to touch these builtin and plugins since Option #1. Separating the localization code form the Option #2 Finding out another code structure that make the minimum change to @annasong20 @natasha41575 Happy to further discuss the proposed two solutions. |
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.
Thanks for the work, Anna! I did some quick reviews mainly focusing on the localizer part. I have two ideas to help making this big feature move forward
return []string{ | ||
"ssh://", "https://", "http://", | ||
} | ||
} |
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.
Using a new method seems not necessary.
Can you use const var?
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.
lint
complains about global variables. Would you like me to override the linter?
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.
qq: can we revert this change as discussed? I think RepoSpec
code refactor and feature changes are better to be done in its own PRs.
api/internal/loctarget/locloader.go
Outdated
// should never happen | ||
log.Fatalf(errors.WrapPrefixf(err, "cannot clean validated file path '%s'", abs).Error()) | ||
} | ||
if !loader.HasRemoteFileScheme(path) && ll.local { |
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.
Shall we deal with the case loader.HasRemoteFileScheme(path)
?
Passing silently (No-op) seems to be out of users' expectations and hard to triage.
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.
localize
doesn't currently put any constraints on remote files. Can you clarify what I should do here?
api/internal/loctarget/util.go
Outdated
// hasRef checks if path url has ref query string parameter | ||
func hasRef(path string) bool { | ||
repoSpec, err := git.NewRepoSpecFromURL(path) | ||
if err != nil { | ||
log.Fatalf("%s: %s", "unable to parse validated root url", err.Error()) | ||
} | ||
return repoSpec.Ref != "" | ||
} | ||
|
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.
super nit: seems to belong to git library. Shall we move this function there?
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'm down to move it, but can I clarify why it belongs with RepoSpec
?
This is a helper function for localize
and doesn't add any functionality to RepoSpec
. I didn't want to clutter RepoSpec
's method pool with a method that makes simple use of RepoSpec
's existing functionality. Also, the log.Fatalf()
is specific to localize
; we only call it because we call hasRef
after loading path, during which a RepoSpec
must have been created.
I originally wanted to put the parseDomain
function (in this file) in RepoSpec
, but it seemed to require refactoring the existing code, which (I believe?) wasn't recommended. #4652 (comment) I'm also down to refactor if time allows.
api/internal/loctarget/util.go
Outdated
func toFSPath(urlPath string) string { | ||
return filepath.Join(strings.Split(urlPath, "/")...) | ||
} |
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 have some further concerns about the risk conditions this function needs to handle. Would like to see some more test coverages to show what the filepaths look like if the url path contains special characters (or invalid file name characters like pipe)
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've added test coverage to the best of my knowledge in this commit: dd324d1 My current (uninformed) approach is to work around illegal file name characters for unix, linux, but leave windows.
I've also been concerned about the following edge cases, but like in this case, would like your feedback on whether they warrant attention:
- same host, but different scheme, userinfo, or port
- org, repo being the dot-segments '.' 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.
Change approve to request changes.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: annasong20 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 |
I totally agree with this. I was not expecting such large changes to the builtin plugins or kusttarget. The only thing I expected from the plugins was the addition of Some of the changes to the plugins seem to be purely stylistic, for example the |
Address feedback, expose errors, and improve error messages
Implement localizer with integration tests and fix lint.
// Acceptable formats include: | ||
// 1. source-path: the basename will become the key name | ||
// 2. source-name=source-path: the source-name will become the key name and | ||
// source-path is the path to the key file. | ||
// Acceptable formats include: | ||
// 1. source-path: the basename will become the key name | ||
// 2. source-name=source-path: the source-name will become the key name and | ||
// source-path is the path to the key file. |
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.
Can you revert this change or run gofmt
?
@@ -116,24 +117,32 @@ func (ll *locLoader) Load(path string) ([]byte, error) { | |||
// New returns a Loader at path if path is a valid localize root. | |||
// Otherwise, New returns an error. | |||
func (ll *locLoader) New(path string) (ifc.Loader, error) { | |||
repoSpec, err := git.NewRepoSpecFromURL(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.
Note to self: check invalid if remote file passed in
If you are still working on this PR and it is not ready for review, could you mark it as draft or WIP? If you do not plan to work on this PR, we should probably close it so that other reviewers don't spend a lot of time looking at it. |
I'm closing this PR because its scope is too large. I'll be splitting this up into smaller, more focused PRs. |
Builds off of #4779. Implements most of localization logic for
kustomize localize
, includinglocalize
destination