Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Yingrjimsch
Copy link

Implementation of Issue 5616
#5616

Copy link

linux-foundation-easycla bot commented Mar 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 18, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @Yingrjimsch!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 18, 2024
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 18, 2024
@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 21, 2024
@Yingrjimsch Yingrjimsch force-pushed the feat/replace-between-delimiters branch from 758a50c to 4210131 Compare March 21, 2024 09:33
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 21, 2024
@Yingrjimsch
Copy link
Author

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.

@Yingrjimsch
Copy link
Author

/assign @ncapps

@Yingrjimsch
Copy link
Author

/assign @varshaprasad96

@olegmayko
Copy link

hi, any ETA on the merge of this PR?

@Yingrjimsch
Copy link
Author

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...

@olegmayko
Copy link

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 vars to replacement recently and found it's not possible for our setup until this or similar feature is available. it's strange that there is not so much noise about this , but maybe noone have tried to migrate yet.

Copy link

@harshsingh32 harshsingh32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@newtondev
Copy link

newtondev commented May 15, 2024

This is a great feature and would love to start using it (kudos for implementing it). There any reviewers that can approve?

@antoooks
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 20, 2024
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))
Copy link
Member

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?

Copy link
Author

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, 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.
  • 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 the Delimiter is empty they swap values. Do you have another suggestion for preprocessing?

Copy link
Member

@varshaprasad96 varshaprasad96 Jun 21, 2024

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?

Copy link
Author

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.

Copy link
Author

@Yingrjimsch Yingrjimsch Jun 27, 2024

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 {
Copy link
Member

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?

Copy link
Author

@Yingrjimsch Yingrjimsch Jun 21, 2024

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 21, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Yingrjimsch
Once this PR has been reviewed and has the lgtm label, please ask for approval from varshaprasad96. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Yingrjimsch Yingrjimsch force-pushed the feat/replace-between-delimiters branch from fbd7efe to f4441a8 Compare June 21, 2024 07:59
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 21, 2024
@koba1t
Copy link
Member

koba1t commented Jun 30, 2024

/hold
Sorry, but I add a comment to the feature request issue.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants