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

prevent all uses of YAML aliases from being overwritten by a transformer #5096

Merged

Conversation

yutaroyamanaka
Copy link
Contributor

@yutaroyamanaka yutaroyamanaka commented Mar 18, 2023

Fixes: #4927

When we use YAML anchors and aliases, all of the aliases point to the same address as a result of DeAnchor(). Therefore, if we try to override the value of one alias with a transformer, it can affect all other aliases that have the same anchor name. To prevent this, I propose that each alias *yaml.Node should point to a unique address by copying it.

#4927 is a specific case for the images transformer. This can be reproduced with all transformers.

Example YAML files:

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: &appName foo
spec:
  template:
    spec:
      containers:
        - name: *appName
          image: *appName
# kustomization.yaml
resources:
  - deployment.yaml
images:
  - name: foo
    newName: bar

Output of this branch

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
spec:
  template:
    spec:
      containers:
      - image: bar
        name: foo

Output of current master

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
spec:
  template:
    spec:
      containers:
      - image: bar
        name: bar

@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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 18, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @yutaroyamanaka. 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 Mar 18, 2023
@k8s-ci-robot k8s-ci-robot requested review from koba1t and mortent March 18, 2023 06:27
@koba1t
Copy link
Member

koba1t commented Mar 29, 2023

/triage accepted
/kind bug
/priority important-soon

/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. triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 29, 2023
@koba1t
Copy link
Member

koba1t commented Mar 29, 2023

Hi @yutaroyamanaka
Thanks for your contribution!

Your PR looks almost good.
So, Could you add more e2e test cases about testing DeAnchor() called from other transformers?

@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 Mar 31, 2023
@yutaroyamanaka
Copy link
Contributor Author

Hi @koba1t

Thank you for your feedback.
I added two other test cases to plugin/builtin/patchtransformer/PatchTransformer_test.go in 690d901 and plugin/builtin/replacementtransformer/ReplacementTransformer_test.go in 8499a24.

@KnVerey
Copy link
Contributor

KnVerey commented Mar 31, 2023

/label tide/merge-method-squash
/approve
/lgtm

@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 Mar 31, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 31, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 31, 2023
@k8s-ci-robot k8s-ci-robot merged commit 42bf3c0 into kubernetes-sigs:master Mar 31, 2023
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. kind/bug Categorizes issue or PR as related to a bug. 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

images feature overrides all uses of YAML anchors used for image name
4 participants