-
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
fix: Allow patches with empty files with multiple newlines or comments #5771
Open
jchanam
wants to merge
3
commits into
kubernetes-sigs:master
Choose a base branch
from
jchanam:fix-allow-patches-with-empty-files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−4
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@stormqueen1990 This is an example of what I mean.
Here I'm testing the input to be a file with only a new line. Based on my new code, this should give no error, but I'm getting a specific error from the tests extra code saying that the input to RunTransformerAndCheckError can't be empty.
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 missing a
go generate
step for this code. Theplugin/builtin/patchtransformer/PatchTransformer.go
file you updated is a scaffold for the plugin generated underapi/internal/builtins/PatchTransformer.go
; therefore, you will need to rungo generate plugin/builtin/patchtransformer/PatchTransformer.go
to update the final built-in plugin code.You can also run the prow checks locally using
make prow-presubmit-check
from the root of the repository.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 so much @stormqueen1990
I've just generated the plugin and pushed the change.
Regarding the test, I run them locally, but I'm given an error that IMO shouldn't happen, as it's complaining of exactly what I want to test:
I'm adding an "empty file" (for kustomize) and with my change, it should work. Could you help me improving this testing scaffolding so it stops complaining about the empty 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.
Hi there, @jchanam! Sorry for the delay in responding. Let me take a look at this and I'll get back to you!
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 again, @jchanam!
I took a deeper look and this test case isn't quite right. If you copy it and paste in a Kustomize version without the regression (e.g. tag
kustomize/v5.1.1
) it still won't pass.Taking a look at the configuration for
RunTransformerAndCheckError
, the first argument of the function refers to the transformer configuration and that cannot be empty under any circumstance:kustomize/api/testutils/kusttest/harnessenhanced.go
Lines 200 to 204 in 7911b2c
The transformer configuration is the blurb that instructs Kustomize how to deal with a patch. In the
PatchTransformer
case, that would be this part of thekustomization.yaml
file:What we want to be empty in this scenario is the patch, i.e. the file to which the transformer configuration refers, not the transformer configuration. The tests that write patch files in this test file are more similar to the scenario you need to emulate (for example,
TestPatchTransformerSmpSidecars
).