Skip to content

PatchTransformer does not support array literal #5806

@alchemistake

Description

@alchemistake

What happened?

I hope I'm doing something wrong than there is a problem with Kustomize

I'm using this file

apiVersion: builtin
kind: PatchTransformer
metadata:
  name: example
target:
  kind: Deployment
patch: |
  - op: add
    path: /spec/template/spec/volumes/-
    value:
      - name: my_example_volume
        emptyDir: {}
  - op: add
    path: /spec/template/spec/containers/0/env/-
    value:
      - name: EXAMPLE_DIR
        value: /etc/wow_example
  - op: add
    path: /spec/template/spec/containers/0/volumeMounts/-
    value:
      - name: my_example_volume-multiproc-dir
        mountPath: /etc/wow_example

and I'm getting this error

add operation does not apply: doc is missing path: "/spec/template/spec/volumes/-": missing value

What did you expect to happen?

I was expecting the volume and env vars in the transformer would be appended to the deployment.

How can we reproduce it (as minimally and precisely as possible)?

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources.yaml
tranformers:
- tranformer.yaml
# transformer.yaml
apiVersion: builtin
kind: PatchTransformer
metadata:
  name: example
target:
  kind: Deployment
patch: |
  - op: add
    path: /spec/template/spec/containers/0/env/-
    value:
      - name: EXAMPLE_DIR
        value: /etc/wow_example
# resources.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
       - env:
         - name: hello
           value: world

Expected output

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
       - env:
         - name: hello
           value: world
         - name: EXAMPLE_DIR
            value: /etc/wow_example

Actual output

Errors out because of path.

Kustomize version

v5.5.0

Operating system

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions