-
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
add edit fix
for patchesStrategicMerge to patches
#4733
add edit fix
for patchesStrategicMerge to patches
#4733
Conversation
ee59de2
to
ab23987
Compare
/assign @natasha41575 |
@koba1t: 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. |
17f2f48
to
f1b15e3
Compare
f1b15e3
to
3f0c213
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.
So sorry for the long delay. Thank you for this change! Some minor comments
api/types/kustomization.go
Outdated
for _, patchStrategicMerge := range k.PatchesStrategicMerge { | ||
// check this patch is file path select. | ||
if strings.Count(string(patchStrategicMerge), "\n") < 1 && | ||
(patchStrategicMerge[len(patchStrategicMerge)-5:] == ".yaml" || patchStrategicMerge[len(patchStrategicMerge)-4:] == ".yml") { |
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.
An easier and more reliable way to check if this is a filepath or not is to try to open it (i.e. os.ReadFile
), and check for error
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 rewrite at 032bf33.
a01afa9
to
7081b22
Compare
7081b22
to
032bf33
Compare
hi @natasha41575 |
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. Very small nit about some formatting in the tests
spec: | ||
template: | ||
spec: | ||
containers: |
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.
same here (and a few other places)
I know it doesn't really matter for these tests, but it's good to make sure our tests have valid input
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 know it doesn't really matter for these tests, but it's good to make sure our tests have valid input
Sorry, I couldn't find that before committing.
I completely agree with your opinion.
I fixed everything.
hi @natasha41575 |
@annasong20 Do you mind giving this PR a review? And as a final check, it would be helpful if you could pull down and build the PR and verify that it does the right thing. Btw, when you are testing, it is expected that it won't work unless the patch file exists. |
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.
if k.PatchesStrategicMerge != nil { | ||
for _, patchStrategicMerge := range k.PatchesStrategicMerge { | ||
// check this patch is file path select. | ||
if _, err := fSys.ReadFile(string(patchStrategicMerge)); err == nil { |
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 don't need to change anything, but just as an FYI, the existing PatchesStrategicMerge
code differentiates between inline and files like this: https://github.com/kubernetes-sigs/kustomize/blob/master/plugin/builtin/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go#L63
Checking for inlines this way doesn't require the file to exist.
`, | ||
}, | ||
} | ||
for _, test := range tests { |
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 we move the loop body into the body of a function passed to t.Run()
? The Run method runs its parameter function as a sub-test, which will display the results as such and isolate failures between sub-tests. We can also pass in test.name
.
Very thorough testing!
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 fixed it at 7c2e884
if diff := cmp.Diff([]byte(test.expected), content); diff != "" { | ||
t.Errorf("%s: Mismatch (-expected, +actual):\n%s", test.name, diff) | ||
} |
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.
Optional nit: We can replace these lines with require.Empty(t, cmp.Diff([]byte(test.expected), content))
since t.Run()
will print the sub-test name and require.Empty()
will print diff
if it isn't 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.
done
@natasha41575 The PR binary works as expected on the following setup:
patchesStrategicMerge:
- deploy.yaml
- |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
env:
- name: CONFIG_FILE_PATH
value: home.yaml
patchesJson6902:
- path: patch1.yaml
target:
kind: Deployment
patches:
- path: patch2.yaml
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
env:
- name: CONFIG_FILE_PATH_2
value: home.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
env:
- name: CONFIG_FILE_PATH_3
value: home.yaml On a different note, I think it'd be helpful for the current code in fix_test.go to check for more than just an error. We should care about warnings that the build failed or that the build output is different. I know they're currently printed because we don't provide resources that match the patch targets, but the warnings could technically be the result of us "fixing" the kustomization incorrectly. It doesn't seem safe to ignore them. Something else that I noticed while testing the binary, but of lesser importance, is that we don't inform users if their initial build was faulty. I found this very confusing because when I saw this warning, I'd assume Not saying we need to address these concerns in this PR, since the code wasn't introduced here. |
Do you think this commit fixes that? |
Hi, @annasong20 |
Yes, perfect! Looks good to me. Will defer to @natasha41575 to approve. |
@natasha41575 Hi, @annasong20 |
/lgtm |
So sorry for the delay! Reviewing this now |
Thanks so much for the fix! This means we can get #4723 in soon as well. This is great. Please feel free to reach out if you are looking for more issues to pick up. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: koba1t, natasha41575 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 |
fix #4706