-
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 error message using replacement wildcard and create option #4577
fix error message using replacement wildcard and create option #4577
Conversation
Hi @koba1t. 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. |
/assign @natasha41575 |
/ok-to-test |
create: true | ||
`, | ||
expectedErr: "cannot support create option in a multi-value target now", | ||
}, | ||
"multiple field paths in target": { |
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.
could you please also add the test from https://github.com/kubernetes-sigs/kustomize/pull/4574/files that I added to replacement_test.go, called "create Job spec"?
I pulled your branch and it looks like something funny is going on when running with that test, it would be great if you could help fix that.
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.
For that case, I think we can do something in the code that's here:
kustomize/api/filters/replacement/replacement.go
Lines 119 to 123 in e5041ba
if target.Options != nil && target.Options.Create { | |
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...)) | |
} else { | |
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath}) | |
} |
We can potentially try something like this:
if target.Options != nil && target.Options.Create && !fieldPathAlreadyExistsInTarget {
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
} else {
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
}
to see if it fixes the problem.
@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. |
kyaml/yaml/fns.go
Outdated
@@ -541,6 +541,9 @@ func (l PathGetter) getFilter(part, nextPart string, fieldPath *[]string) (Filte | |||
case part == "-": | |||
// part is a hyphen | |||
return GetElementByIndex(-1), nil | |||
case part == "*": | |||
// part is a asterisk | |||
return nil, errors.Errorf("cannot support create option in a multi-value target now") |
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.
Won't it be possible for someone to be attempting to use PathGetter
with an asterisk but without the create option? I think this error message needs to be about wildcard support rather than create mode specifically because of that (and replacements may need to augment the error to clarify what the problem is in that specific flow).
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.
+1
The other option is to move the check into the replacement filter, in replacements.go
you can throw this error if create
is true and the path contains *
.
Also suggest removing the word "now"
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 I fix it to 01ab069
// So, if create option is set, we fallback to PathGetter. | ||
for _, f := range fieldPath { | ||
if f == "*" { | ||
return errors.New("cannot support create option in a multi-value target") |
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 can just add //nolint:goerr113
to the end of this line. I don't think we need to worry about this dynamic error here since the rest of the code is sprinkled with dynamic errors.
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!
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
/approve
Thanks for this PR!
Do you have the bandwidth to work on what I described in this comment #4577 (comment) over the next couple of weeks?
If so, please submit a PR with the test and a fix. Otherwise let me know I will probably try to work on it myself when I can.
[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 error message using both wildcard and create option on replacement.
Temporarily fix to #4561.