Skip to content

Draft: Detect no matching resources #5917

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

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

Conversation

adoramshoval
Copy link

@adoramshoval adoramshoval commented May 23, 2025

This PR aims to resolve the rotten issue no. #4379 .
As #4715 has rotten as well, this PR is continuing the contributor (@laxmikantbpandhare ) work maintaining the already existing commits.

This PR adds the enforcement for resources selectors not matching any resources at all by throwing an error if no resource has been selected.
A new option has been added, allowNoTargetMatch, allowing to avoid this error, which will cause a warning to be printed and resources to rendered if no further error is encountered.

The Options attribute has been replaced from a map[string]bool to a new type under the api directory named PatchArgs. This will provide a better documentation and will help to avoid typing errors.

NOTE: The changes done in this PR have been requested in the PR mentioned above by @annasong20 .

@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-sigs/prow repository.

Copy link

linux-foundation-easycla bot commented May 23, 2025

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 May 23, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adoramshoval
Once this PR has been reviewed and has the lgtm label, please assign knverey for approval. For more information see the 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

@k8s-ci-robot
Copy link
Contributor

Welcome @adoramshoval!

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
Copy link
Contributor

Hi @adoramshoval. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 23, 2025
@adoramshoval adoramshoval force-pushed the detect-no-matching-resources branch from d88131f to 015d04b Compare May 23, 2025 20:57
@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 May 23, 2025
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Hello there, @adoramshoval! Thanks for your contribution.

It's a good idea to refactor the code to use an object type instead of a map for patch options. Could we perhaps have that split out in a separate PR (with its tests), as it would result in a smaller change set to be reviewed for both PRs?

I also have a question: it looks like the new option allowNoTargetMatch is false by default. That would amount to a breaking change in the current kustomize flow, as current kustomizations with no matching resources do not fail to apply, but would start failing once this is merged. Could you please confirm that would be the case?

@adoramshoval
Copy link
Author

Hi @stormqueen1990 , thanks for your reply.

It's a good idea to refactor the code to use an object type instead of a map for patch options. Could we perhaps have that split out in a separate PR (with its tests), as it would result in a smaller change set to be reviewed for both PRs?

That is correct, thanks, I will work on that.

I also have a question: it looks like the new option allowNoTargetMatch is false by default. That would amount to a breaking change in the current kustomize flow, as current kustomizations with no matching resources do not fail to apply, but would start failing once this is merged. Could you please confirm that would be the case?

Yes, that is the case. Is there a certain work flow I should go through in case of a breaking change?

adoramshoval and others added 4 commits June 13, 2025 08:42
This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options.
Rebase laxmikantbpandhare commits on top of master
@adoramshoval adoramshoval force-pushed the detect-no-matching-resources branch from 015d04b to a7d3da1 Compare June 14, 2025 08:44
@adoramshoval adoramshoval changed the title Detect no matching resources Draft: Detect no matching resources Jun 14, 2025
@adoramshoval
Copy link
Author

Hi @stormqueen1990 ,
I have created another PR (#5930 ) which contains only the addition of the PatchArgs API type as requested.
This PR was marked as draft and it is based on the other PR including the same commit.
I hope I did everything as you expected, let me know if anything is wrong and I'll fix it.

@stormqueen1990
Copy link
Member

Yes, that is the case. Is there a certain work flow I should go through in case of a breaking change?

Hi there, @adoramshoval!

In this case, we'll need some input from the current maintainers.
@koba1t and @varshaprasad96, could you please confirm whether this change requires extra steps due to being a breaking one?

@stormqueen1990
Copy link
Member

Hi @stormqueen1990 , I have created another PR (#5930 ) which contains only the addition of the PatchArgs API type as requested. This PR was marked as draft and it is based on the other PR including the same commit. I hope I did everything as you expected, let me know if anything is wrong and I'll fix it.

Thank you very much! I'll take a look at the new PR soon.

@koba1t
Copy link
Member

koba1t commented Jun 16, 2025

/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 16, 2025
…nsformer

This commit makes use of the new PatchArgs type and the new Patch option `allowNoTargetMatch`.
This option, if true, allows rendering kustomization even if no resource is matched against the given target, while printing a warning to stderr.
By default this option is set to false meaning that if no resource is matched against the given target an error is raised.

This commit includes the extra tests to test this new feature.
@adoramshoval adoramshoval force-pushed the detect-no-matching-resources branch from a7d3da1 to 8da8556 Compare June 19, 2025 10:32
@adoramshoval
Copy link
Author

/ok-to-test

Hi @koba1t , I have fixed the errors. Is it possible to re-run the tests?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 26, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-sigs/prow repository.

@adoramshoval
Copy link
Author

@koba1t , @stormqueen1990 allow me some time while I make some changes based on #5930 .

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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

5 participants