Skip to content

feat: add PatchArgs API type to populate patch options #5930

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 1 commit into
base: master
Choose a base branch
from

Conversation

adoramshoval
Copy link

This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options and should prevents human typing errors.
It is the base branch for an already existing branch adding the option allowNoTargetMatch, see #5917 .

This was requested as part of #4715 , see https://github.com/kubernetes-sigs/kustomize/pull/4715/files#r1278209456.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 14, 2025
@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 Jun 14, 2025
@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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 14, 2025
@sarab97
Copy link
Contributor

sarab97 commented Jun 22, 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 22, 2025
@sarab97
Copy link
Contributor

sarab97 commented Jun 22, 2025

This looks good! The nil handling for Options is well implemented, excellent work.
However, I'd suggest alternative of ensuring the Options struct always exists instead of allowing nil pointers. Unlike Target, this replaces an existing map[string]bool workflow, so checking for struct nil before accessing members might break existing workflows that expect options to always be available and add unnecessary validation overhead at each access point

Since this changes a map structure, it would be safer to guarantee the Options struct always exists (even if empty) to ensure existing workflows aren't affected.

@adoramshoval
Copy link
Author

This looks good! The nil handling for Options is well implemented, excellent work. However, I'd suggest alternative of ensuring the Options struct always exists instead of allowing nil pointers. Unlike Target, this replaces an existing map[string]bool workflow, so checking for struct nil before accessing members might break existing workflows that expect options to always be available and add unnecessary validation overhead at each access point

Since this changes a map structure, it would be safer to guarantee the Options struct always exists (even if empty) to ensure existing workflows aren't affected.

Hi @sarab97 , thanks for your review!
Before I jump in, let me make sure I got you right.
Instead of passing Options as a pointer, you would like me to pass its value so it would get intialized with default values, correct?
I think that makes a lot of sense, thanks a lot 🤗 .

@adoramshoval
Copy link
Author

Hi, I have stummbled upon an issue while trying to reimplement the Patch struct now using the value of PatchArgs and I would like your help.
Since a struct does not have a zero value, having the value of PatchArgs adds an empty Options: {} field to a processed kustomization.yaml file going through the localizer which causes some tests to fail, for example TestTargetNestedInScope.

The test expects:

apiVersion: kustomize.config.k8s.io/v1beta1
        kind: Kustomization
        patches:
        - patch: |-
            - op: replace
              path: /some/existing/path
              value: new value
          target:
            kind: Deployment
            labelSelector: env=dev

but the actual output is:

apiVersion: kustomize.config.k8s.io/v1beta1
        kind: Kustomization
        patches:
        - options: {}
          patch: |-
            - op: replace
              path: /some/existing/path
              value: new value
          target:
            kind: Deployment
            labelSelector: env=dev

Notice the added Options: {}.

@sarab97 , @koba1t , @stormqueen1990
I would like your assistance on how to proceed from here since I am not sure which direction would be better.
Also, let me know if this change isn't necessary as a whole.

@adoramshoval
Copy link
Author

Any thoughts? @sarab97 , @koba1t

@stormqueen1990
Copy link
Member

@sarab97 , @koba1t , @stormqueen1990 I would like your assistance on how to proceed from here since I am not sure which direction would be better. Also, let me know if this change isn't necessary as a whole.

Hi there, @adoramshoval!

I did some testing with a simpler piece of code and noticed the same behaviour. Your assessment makes sense to me: a struct cannot have a zero value and therefore will be serialized into YAML/JSON even when not explicitly specified.

@sarab97 would you agree to go back to the original implementation with a pointer so we can keep the serialization behaviour of kustomize?

@sarab97
Copy link
Contributor

sarab97 commented Jul 25, 2025

@sarab97 would you agree to go back to the original implementation with a pointer so we can keep the serialization behaviour of kustomize?

If its fine by you yeah sure, even though it adding option as empty it is not expected. So Im guessing the original approach is the only way.

@adoramshoval
Copy link
Author

Then I'll proceed with this.
Thanks guys!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 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 koba1t 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 k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 8, 2025
This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options.
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 2025
@adoramshoval
Copy link
Author

/retest

@adoramshoval
Copy link
Author

I made the changes, I hope this won't fail lint tests now.
Notice that I also modified plugin/builtin/patchtransformer/PatchTransformer.go, I fingured it makes more sense for it to also include the the change I am introduing here.
Let me know what do you think.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants