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 error during expansion of !!merge <<: anchor tags #4383

Merged
merged 24 commits into from Mar 23, 2022

Conversation

RafaeLeal
Copy link
Contributor

Problem

Using yamls with <<: *anchor with or without the tag !!merge tag is leading to an error:

json: unsupported type: map[interface {}]interface {}

A lot of apps distributes YAMLs that use that, so even if you're not using it, you may rely on some distribution like Tekton's or Knative's:

Solution

I'm not familiar with the code base, but I tried to understand where we were doing the de-anchoring following this PR
https://github.com/kubernetes-sigs/kustomize/pull/4187/files

Related Issues

@k8s-ci-robot
Copy link
Contributor

@RafaeLeal: 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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 11, 2022

CLA Signed

The committers are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @RafaeLeal!

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 @RafaeLeal. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 11, 2022
@RafaeLeal
Copy link
Contributor Author

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jan 11, 2022
@RafaeLeal
Copy link
Contributor Author

I believe we have two corner cases that we need to take a look:
One is that we're currently removing comments because we are rebuilding that node structure, and other is that we are no longer serializing json correctly.

The first one I believe we can manage, just need to think about the possible cases. We could have, as simple comment as possible:

apiVersion: v1
kind: MergeTagTest
metadata:
  name: test
spec:
  color:
    # red color
    rgb: "#FF0000"

And that is simple enough, but we could also have comments on merge tags, and we need to think about it.

apiVersion: v1
kind: MergeTagTest
metadata:
  name: test
spec:
  color: &base-color
    # red color
    rgb: "#FF0000"
  primaryColor:
    # use the same base color
    <<: *base-color

and then we expand, we should decide:

  • Should we keep comments at all?
  • Should we copy the comments when de-anchoring?
  • How we are going to merge comments?

On merge comments, we have some other corner cases:

  • merging line comments
color: &base-color
  rgb: "#FF0000" # red color
primaryColor:
  <<: *base-color # use same base color 

We have a couple of options.. we could transform to head comment.. and we can decide if we want to transform one or both:

color: 
  rgb: "#FF0000" # red color
primaryColor:
  # red color
  rgb: "#FF0000" # use same base color 

we could also adopt a delimiter

primaryColor:
  rgb: "#FF0000" # red color; use same base color 
  • ordering problem
color: &base-color
  # red color
  rgb: "#FF0000" 
primaryColor: &primary-color
  # use same base color
  <<: *base-color  
  alpha: 0.5
secondaryColor:
  # mixing colors
  <<: *base-color
  <<: *primary-color

If we do decide to copy the comments, we are going to need to deal with how we order that.. and we can just get all merge comments on top of the mapping node.

secondaryColor:
  # red color
  # use same base color
  # mixing colors
  rgb: "#FF0000"
  alpha: 0.5

Let me know what you think

@RafaeLeal
Copy link
Contributor Author

On the other problem, it seems that for some reason I broke the json serialization.. It's failing the TestMoreRNodesFromBytes/goodJson test and other related ones.. I'm not sure how json is dealt, but I'm assuming I broke some metadata when rebuilding the node structure.

@natasha41575
Copy link
Contributor

/cc
/cc @KnVerey

@RafaeLeal
Copy link
Contributor Author

On the other problem, it seems that for some reason I broke the json serialization.. It's failing the TestMoreRNodesFromBytes/goodJson test and other related ones.. I'm not sure how json is dealt, but I'm assuming I broke some metadata when rebuilding the node structure.

I managed to fix this adding a new yaml filter MapEntrySetter... this way we can keep the same Style

@natasha41575
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jan 29, 2022
@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 Feb 8, 2022
kyaml/internal/forked/github.com/go-yaml/yaml/yaml.go Outdated Show resolved Hide resolved
kyaml/yaml/rnode.go Outdated Show resolved Hide resolved
kyaml/yaml/rnode.go Show resolved Hide resolved
kyaml/yaml/rnode_test.go Show resolved Hide resolved
kyaml/yaml/rnode_test.go Show resolved Hide resolved
kyaml/yaml/rnode.go Outdated Show resolved Hide resolved
kyaml/yaml/fns.go Outdated Show resolved Hide resolved
kyaml/yaml/fns.go Show resolved Hide resolved
Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

I have a couple new observations, but only the question about unhandled errors is a blocker for me. Otherwise this is ready to go!

kyaml/yaml/rnode.go Show resolved Hide resolved
kyaml/yaml/rnode.go Outdated Show resolved Hide resolved
kyaml/yaml/rnode.go Show resolved Hide resolved
kyaml/yaml/rnode.go Outdated Show resolved Hide resolved
@KnVerey
Copy link
Contributor

KnVerey commented Mar 23, 2022

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey, RafaeLeal

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 23, 2022
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 23, 2022
@k8s-ci-robot k8s-ci-robot merged commit 97de780 into kubernetes-sigs:master Mar 23, 2022
koba1t pushed a commit to koba1t/kustomize that referenced this pull request Apr 14, 2022
…igs#4383)

* WIP

* Fix merge corner cases

* Add test for explicit !!merge tag

* Fix tests

* Cleanup

* Cleanup

* Fix deanchoring lists

* Add test case for keeping comments

* Add MapEntrySetter and fix json marshalling after deanchoring

* Keep duplicated keys

* Move MergeTag definition to yaml alias

* Remove go-spew from api

* Add support for sequence nodes on merge tags

* Add docstring to MapEntrySetter.Key

* Add docstring to MapEntrySetter struct

* Add tests to MapEntrySetter

* Fix duplicate merge key

* Revert whitespace changes on forked go-yaml

* Remove AssocMapEntry function

* Refactoring merge order

* Return errors on VisitFields and PipeE

* Add tests for each non-conforming map merges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants