-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: added first draft of replacement between delimiter #5617
base: master
Are you sure you want to change the base?
feat: added first draft of replacement between delimiter #5617
Conversation
Welcome @Yingrjimsch! |
Hi @Yingrjimsch. 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. |
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. |
758a50c
to
4210131
Compare
Edit: I decided to add a fulltext replacement as well because it was very similar to the start and enddelimiter. Should not be too much to review and is pretty straightforward. |
/assign @ncapps |
/assign @varshaprasad96 |
hi, any ETA on the merge of this PR? |
I tried via Slack and Assigning to find someone but until now I got sadly no reaction... |
Hi @Yingrjimsch thanks for your contribution, I have been checked how to migrate from |
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
This is a great feature and would love to start using it (kudos for implementing it). There any reviewers that can approve? |
/ok-to-test |
if options.Delimiter == "" { | ||
return nil, fmt.Errorf("delimiter needs to be set if enddelimiter is set") | ||
} | ||
re := regexp.MustCompile(regexp.QuoteMeta(options.Delimiter) + `(.*?)` + regexp.QuoteMeta(options.EndDelimiter)) |
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.
This seems to be a bit fragile:
- We assume that delimiter and end delimiter are in pairs, but this may not be the case always.
- Also what happens when delimiters are not in expected order, or there are nested delimiters.
If not for nested delimiters, for the other cases, can we do any kind of pre-processing?
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.
@varshaprasad96 thank you for the feedback.
- The option is that
Delimiter
comes alone, in this case it stays like it is today, theEndDelimiter
should not be used without aDelimiter
if so we return an error and if they are used in combination, the value in between them is loaded. If I'm not mistaken all cases should be handled. - The delimiters should always be in expected order because their key (delimiter or enddelimiter) allow us to define the order.
- To make it less fragile we could do a preprocessing, if the
EndDelimiter
is set and theDelimiter
is empty they swap values. Do you have another suggestion for preprocessing?
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.
The option is that Delimiter comes alone, in this case it stays like it is today, the EndDelimiter should not be used without a Delimiter if so we return an error and if they are used in combination, the value in between them is loaded. If I'm not mistaken all cases should be handled.
It looks like we do have a check for that. But what happens when there are unequal number of delimiters and end-delimiters? The regex would still compile, but I'm wondering that there would be some unexpected behaviours? Which is why would it be better if we count for each of those occurrences to ensure they work appear as pairs?
To make it less fragile we could do a preprocessing, if the EndDelimiter is set and the Delimiter is empty they swap values. Do you have another suggestion for preprocessing?
I think this looks good the way it is for now, where we error out if delimiter is not set when end delimiter is.
The delimiters should always be in expected order because their key (delimiter or enddelimiter) allow us to define the order.
Can we have checks to ensure that they are in the order as expected, especially when there is a nested scenario - where we have multiple of delimiters and enddelimiters?
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.
@varshaprasad96 I will look into this this week and give you a feedback. If I see a possibility to ensure the order and the amount of delimiters I would implement it so you can review it.
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 @varshaprasad96 I've looked into it and wanted to ask if you could provide a nested example for me. As I have seen the delimiters are used in FieldOptions
https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/replacement.go#L67 which consists of primitive datatypes variables, therefore I don't see how multiple delimiters or nesting could accure. The replacement consists of one SourceSelector
and multiple TargetSelector
everyone of these types contain exactly one FieldOptions
type.
If I am missing something just tell me and I will look into it.
return strings.Join(tv, delimiter) | ||
} | ||
|
||
func getByRegex(regex string, target string, source string, index int) string { |
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 both these are fragile string manipulation methods, can we have separate tests to verify these and ensure we are capturing the edge cases?
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.
@varshaprasad96 I've written some edge case tests but if you want I can add some tests that handle these functions in specific
EDIT: I've added some tests for the regex function. I hope this is what you imagined. Let me know if you want/need more tests
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Yingrjimsch 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 |
fbd7efe
to
f4441a8
Compare
/hold |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
Implementation of Issue 5616
#5616