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

Allow setting every array element in replacements #4424

Conversation

koba1t
Copy link
Member

@koba1t koba1t commented Jan 26, 2022

Implement to #4053.
And resolve #4414 (comment) and #4391.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 26, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @koba1t. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 26, 2022
@koba1t
Copy link
Member Author

koba1t commented Jan 28, 2022

/assign @phanimarupaka

@natasha41575
Copy link
Contributor

/ok-to-test
/assign

@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 Jan 28, 2022
@natasha41575
Copy link
Contributor

Would you mind also adding a test to https://github.com/kubernetes-sigs/kustomize/blob/master/api/filters/replacement/replacement_test.go to add some e2e coverage? Thank you for working on this

@k8s-ci-robot
Copy link
Contributor

@koba1t: 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 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 Jan 30, 2022
- name: deployment-name
value: sample-deploy`,
},
"list index contains '*' character": {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the difference between this test and the above test?

Also, the test seems not to be passing.

Copy link
Member Author

@koba1t koba1t Feb 2, 2022

Choose a reason for hiding this comment

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

@koba1t
Copy link
Member Author

koba1t commented Feb 2, 2022

Sorry for the delay to reply.
But, I found a problem with this code when writing test code.

I think "replacements" couldn't replace for the target to multi values.

e.g.

source

# deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: sample-deploy
  name: sample-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sample-deploy
  template:
    metadata:
      labels:
        app: sample-deploy
    spec:
      containers:
      - image: nginx
        name: main
        env:
        - name: deployment-name
          value: XXXXX
        - name: foo
          value: bar
      - image: nginx
        name: sidecar
        env:
        - name: deployment-name
          value: YYYYY
# kustomization.yaml
resources:
  - deploy.yaml

replacements:
- source:
    kind: Deployment
    name: sample-deploy
    fieldPath: metadata.name
  targets:
  - select:
      kind: Deployment
    fieldPaths:
    - spec.template.spec.containers.[image=nginx].env.[name=deployment-name].value

result

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: sample-deploy
  name: sample-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sample-deploy
  template:
    metadata:
      labels:
        app: sample-deploy
    spec:
      containers:
      - env:
        - name: deployment-name
          value: sample-deploy
        - name: foo
          value: bar
        image: nginx
        name: main
      - env:
        - name: deployment-name
          value: YYYYY
        image: nginx
        name: sidecar

It's only to replace the first element in deploy.yaml.

I think it's needed to fix when using this function. And I'm trying it now.

@koba1t
Copy link
Member Author

koba1t commented Feb 3, 2022

Hello @natasha41575.
Every test case was passing. I think this work is complete.

Sorry for to delay.
If you have time, please re-check this PR.

@natasha41575
Copy link
Contributor

If you have time, please re-check this PR.

Thanks for the update! I have been out for a few days, will try to take a look soon.

Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

Some very minor nits, apart from that LGTM.

@@ -119,20 +119,42 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
if target.Options != nil && target.Options.Create {
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
} else {
t, err = node.Pipe(yaml.Lookup(fieldPath...))
// t, err = node.Pipe(yaml.Lookup(fieldPath...))
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I'll delete it.

@@ -796,6 +803,12 @@ func SplitIndexNameValue(p string) (string, string, error) {
return parts[0], parts[1], nil
}

// IsMatchEveryIndex returns true if p is matching every elements.
// e.g. "*"
func IsMatchEveryIndex(p string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest changing the name here to IsWildcard and moving this up to line 791 to keep the IsXXXX functions together

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. I fix it.

@koba1t
Copy link
Member Author

koba1t commented Feb 9, 2022

I fix any mistake from your review and add the above testcase(#4424 (comment)).

@natasha41575
Copy link
Contributor

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 10, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: koba1t, natasha41575

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 Feb 10, 2022
@k8s-ci-robot k8s-ci-robot merged commit ff40460 into kubernetes-sigs:master Feb 10, 2022
@koba1t koba1t deleted the feature/allow_setting_every_array_element_in_replacements branch February 10, 2022 02:23
@nprokopic
Copy link

So nice to see this implemented, thanks @koba1t! 🎉

@afirth
Copy link
Contributor

afirth commented Feb 17, 2022

you rock @koba1t

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/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.

Support the ability to replace the image registry domain
6 participants