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

Fix bug with merge2 with null values #5365

Closed

Conversation

shuheiktgw
Copy link

@shuheiktgw shuheiktgw commented Oct 9, 2023

Related issues

Fixes #5031

Problem

#4890 originally introduced the problem. The change removes the null tag from the target nodeto preserve the null value, and it works fine if users only merge the files once. However, a problem occurs if users try to merge another file to the output since the node, which used to be tagged as null, does not have any tags attached and looks like a plain ScalarRNode from kyaml's perspective. As a result, the FieldSetter adds DoubleQuotedStyle to the node that used to be tagged as null
, and that leads to #5031.

I've added a test case called TestMerge_null to demonstrate the problem, so please take a look at it as well.

Proposed changes

The original problem was that we could not return null nodes from the Merger#VisitMap since then the FieldSetter#Filter removed them. In this PR, I've changed the FieldSetter#Filter and stopped deleting null nodes. Instead, when we want to remove the nodes, we can simply return walk.ClearNode.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 9, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shuheiktgw
Once this PR has been reviewed and has the lgtm label, please assign koba1t for approval. 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

@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 Oct 9, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @shuheiktgw. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 9, 2023
@@ -725,7 +725,7 @@ func (s FieldSetter) Filter(rn *RNode) (*RNode, error) {
}

// Clear the field if it is empty, or explicitly null
if s.Value == nil || s.Value.IsTaggedNull() {
Copy link
Author

@shuheiktgw shuheiktgw Oct 10, 2023

Choose a reason for hiding this comment

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

There are three possible ways to set s.Value.

  1. Set the Value field directly
  2. Use the SetField function
  3. Use the Set function

I've checked every use case and found two cases in which s.Value could be null.

  1. Walker#walkMap
  2. ByteReader#decode

So I need to investigate the two cases further to clarify how this change affect them...

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 22, 2024
matthewhughes934 added a commit to matthewhughes934/kustomize that referenced this pull request Jan 28, 2024
Related issues:

* kubernetes-sigs#5031
* kubernetes-sigs#5171

After noting this behaviour was not present in
d89b448 a `git bisect` pointed to the
change 1b7db20. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a special flag node that is `null` but never
removed during merges. The added `TestApplySmPatch_Idempotency` test
verifies this behaviour. However, this approach  will may change the
value of the node in the output, e.g. if originally there was `field: ~`
it would be replaced by `field: null`. The added test case in
`kyaml/yaml/merge2/scalar_test.go` demonstrates this behaviour (this
test currently fails as I expect the desired outcome is to preserve the
null marker)

See also kubernetes-sigs#5365 for an
alternative approach
matthewhughes934 added a commit to matthewhughes934/kustomize that referenced this pull request Jan 28, 2024
Related issues:

* kubernetes-sigs#5031
* kubernetes-sigs#5171

After noting this behaviour was not present in
d89b448 a `git bisect` pointed to the
change 1b7db20. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a special flag node that is `null` but never
removed during merges. The added `TestApplySmPatch_Idempotency` test
verifies this behaviour. However, this approach  will may change the
value of the node in the output, e.g. if originally there was `field: ~`
it would be replaced by `field: null`. The added test case in
`kyaml/yaml/merge2/scalar_test.go` demonstrates this behaviour (this
test currently fails as I expect the desired outcome is to preserve the
null marker)

See also kubernetes-sigs#5365 for an
alternative approach
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 21, 2024
matthewhughes934 added a commit to matthewhughes934/kustomize that referenced this pull request Mar 5, 2024
Related issues:

* kubernetes-sigs#5031
* kubernetes-sigs#5171

After noting this behaviour was not present in
d89b448 a `git bisect` pointed to the
change 1b7db20. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a new attribute on `RNode`s that is checked before
clearing any node we should keep. The added
`TestApplySmPatch_Idempotency` test verifies this behaviour.

See also kubernetes-sigs#5365 for an
alternative approach
matthewhughes934 added a commit to matthewhughes934/kustomize that referenced this pull request Mar 9, 2024
Related issues:

* kubernetes-sigs#5031
* kubernetes-sigs#5171

After noting this behaviour was not present in
d89b448 a `git bisect` pointed to the
change 1b7db20. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a new attribute on `RNode`s that is checked before
clearing any node we should keep. The added
`TestApplySmPatch_Idempotency` test verifies this behaviour.

See also kubernetes-sigs#5365 for an
alternative approach
@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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2024
@stormqueen1990
Copy link
Member

Superseded by #5519

@stormqueen1990
Copy link
Member

/close

@k8s-ci-robot
Copy link
Contributor

@stormqueen1990: Closed this PR.

In response to this:

/close

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.

antoooks pushed a commit to antoooks/kustomize that referenced this pull request Mar 24, 2024
Related issues:

* kubernetes-sigs#5031
* kubernetes-sigs#5171

After noting this behaviour was not present in
d89b448 a `git bisect` pointed to the
change 1b7db20. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a new attribute on `RNode`s that is checked before
clearing any node we should keep. The added
`TestApplySmPatch_Idempotency` test verifies this behaviour.

See also kubernetes-sigs#5365 for an
alternative approach
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/work-in-progress Indicates that a PR should not merge because it is a work in progress. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

Creation timestamp set to invalid value "null" when using kustomize v5.0.0
4 participants