kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
11k stars 2.25k forks source link

Support for multiple paths using JSON patch #5107

Closed gabricc closed 1 year ago

gabricc commented 1 year ago

Eschewed features

What would you like to have added?

Hi everyone! It would be great if we could specify multiple paths in a single op, add/replace operation. Lot of times we have paths that require the same value, and we have to repeat it a lot of times.

Why is this needed?

This is an example where a lot of paths use the same deployment-name value. It makes the kustomization.yaml too repetitive:

bases:
- ../../../base-workers

patches:
- target:
    kind: Deployment
  patch: |-
    - op: replace
      path: /metadata/name
      value: deployment-name
    - op: replace
      path: /metadata/namespace
      value: director
    - op: replace
      path: /metadata/labels/app
      value: deployment-name
    - op: replace
      path: /spec/template/metadata/labels/app
      value: deployment-name
    - op: replace
      path: /spec/template/spec/containers/0/name
      value: deployment-name
    - op: replace
      path: /spec/template/spec/containers/0/image
      value: registry
    - op: replace
      path: /spec/template/spec/containers/0/command
      value: ["java", "..."]
    - op: replace
      path: /spec/template/spec/containers/0/env/1
      value:
        name: DD_SERVICE
        value: deployment-name
    - op: replace
      path: "/spec/template/spec/containers/0/envFrom/0"
      value:
        configMapRef:
          name: deployment-name-env-variables
    - op: replace
      path: /spec/selector/matchLabels/app
      value: deployment-name
    - op: replace
      path: "/spec/template/metadata/labels/tags.datadoghq.com~1env"
      value: production
    - op: replace
      path: "/spec/template/metadata/labels/tags.datadoghq.com~1service"
      value: deployment-name
    - op: replace
      path: "/spec/selector/matchLabels/tags.datadoghq.com~1service"
      value: deployment-name

It would be great if we could do something like:

    - op: replace
      paths: {"/metadata/name", "/metadata/labels/app", "/spec/template/metadata/labels/app"}
      value: deployment-name

Can you accomplish the motivating task without this feature, and if so, how?

Yes, but the code gets too repetitive.

What other solutions have you considered?

I have considered using strategic merge patch, but it doesn’t fit so good to my scenario.

Anything else we should know?

Thanks!

Feature ownership

KnVerey commented 1 year ago

The JSON patch mechanism we use is an IETF standard: https://datatracker.ietf.org/doc/html/rfc6902/. As such, its syntax and operations are not something that Kustomize should change.

/triage out-of-scope /close

k8s-ci-robot commented 1 year ago

@KnVerey: Closing this issue.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5107#issuecomment-1485846239): >The JSON patch mechanism we use is an IETF standard: https://datatracker.ietf.org/doc/html/rfc6902/. As such, its syntax and operations are not something that Kustomize should change. > >/triage out-of-scope >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.