<p>I'm trying to use patching in Kustomize to modify Kubernetes resources and I'm wondering if there is a neat way to update every item of a list.</p>
<p>Here is the yaml that I'd like to customize:</p>
<pre><code>apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  annotations:
  name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
  - v1
  clientConfig:
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-binding
- admissionReviewVersions:
  - v1
  clientConfig:
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-exchange
- admissionReviewVersions:
  - v1
  clientConfig:
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-federation
</code></pre>
<p>And here is the end effect that I want to achieve (see <code>NEWVALUE</code>):</p>
<pre><code>apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  annotations:
  name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
  - v1
  clientConfig:
    NEWVALUE: value
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-binding
- admissionReviewVersions:
  - v1
  clientConfig:
    NEWVALUE: value
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-exchange
- admissionReviewVersions:
  - v1
  clientConfig:
    NEWVALUE: value
    service:
      name: webhook-service
      namespace: rabbitmq-system
      path: /validate-rabbitmq-com-v1beta1-federation
</code></pre>
<p>I'm fully aware of a Json6902 patch but it only allows me to modify one index at a time:</p>
<pre><code>- op: add
  path: /webhooks/0/clientConfig/NEWVALUe
  value: value
</code></pre>
<p>Is there a way to modify every element in a fashion similar to a for loop or do I have to specify each index manually?</p>

<p>According to what discussed <a href="https://github.com/kubernetes-sigs/kustomize/issues/4561" rel="nofollow noreferrer">here</a> they don't have support for such case yet. when they add it you can do something like this:</p>
<pre><code>kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1

resources:
- validating-webhook.yaml
- configmap.yaml

replacements:
- source:
    kind: ConfigMap
    name: cofignmap
    fieldPath: data.NEWVALUE
  targets:
  - select:
      name: validating-webhook-configuration
      kind: ValidatingWebhookConfiguration
    fieldPaths:
      - webhooks.*.clientConfig.NEWVALUE
    options:
      create: true
</code></pre>
<p>configMap:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: cofignmap
data:
  NEWVALUE: value
</code></pre>
<p>you can read about replacements in the <a href="https://github.com/kubernetes-sigs/cli-experimental/blob/master/site/content/en/references/kustomize/kustomization/replacements/_index.md" rel="nofollow noreferrer">docs</a></p>
