<p>I'm trying to add envs injection based on <code>envFrom</code></p>
<p>A simplified structure looks something like that:</p>
<pre><code>├── base
│   ├   ─ backend
    │   ├── backend.properties
    │   ├── app1
    │   │   ├── app1_backend.properties
        ├   ── deployment.yaml
    │   │   ├── ingress.yaml
    │   │   ├── kustomization.yaml
    ├── common.properties
    ├── frontend
    │   ├── app1
        │   ├── app1_frontend.properties
    │   │   ├── deployment.yaml
    │   │   ├── ingress.yaml
    │   │   ├── kustomization.yaml
    │   │   └── service.yaml
    │   ├── frontend.properties
    │   └── kustomization.yaml
    └── kustomization.yaml
</code></pre>
<p>I would like to generate properties on the main level(common), backend/frontend level, and particular app level.
So I was trying to add the following patch on main level and it works:</p>
<pre><code>  - op: add
    path: /spec/template/spec/containers/0/envFrom
    value:
    - configMapRef:
        name: common-properties
</code></pre>
<p>and following code to nested directories(backend/frontend/particular app)</p>
<pre><code>- op: add
  path: &quot;/spec/template/spec/containers/0/envFrom/-&quot;
  value:
    configMapRef:
      name: backend-properties
</code></pre>
<p>But it doesn't work with the following error:</p>
<pre><code>add operation does not apply: doc is missing path: &quot;/spec/template/spec/containers/0/envFrom/-&quot;: missing value
</code></pre>
<p>I have seen some examples on GitHub where that syntax was used: <a href="https://github.com/search?l=YAML&amp;p=1&amp;q=%2Fspec%2Ftemplate%2Fspec%2Fcontainers%2F0%2FenvFrom%2F-&amp;type=Code" rel="nofollow noreferrer">https://github.com/search?l=YAML&amp;p=1&amp;q=%2Fspec%2Ftemplate%2Fspec%2Fcontainers%2F0%2FenvFrom%2F-&amp;type=Code</a> (you have to be logged in to see results) And I'm not sure this stopped work on specific Kustomize version(I'm using the newest version - 4.5.3) or it never worked</p>
<p>I have already written some Kustomize patches and syntax with <code>/-</code> to resources usually worked fine to resources that already exist on the manifest.
It's possible to inject that <code>envFrom</code> on different levels?</p>

rafal1337
<p>It's hard to diagnose your problem without a reproducible example, but if I start with this <code>Deployment</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    spec:
      containers:
        - name: example
          image: docker.io/alpine:latest
          envFrom:
            - configMapRef:
                name: example-config
</code></pre>
<p>And use this <code>kustomization.yaml</code>, which includes your patch without
changes:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml

patches:
  - target:
      kind: Deployment
      name: example
    patch: |-
      - op: add
        path: &quot;/spec/template/spec/containers/0/envFrom/-&quot;
        value:
          configMapRef:
            name: backend-properties
</code></pre>
<p>Then everything seems to work and I get the resulting output from
<code>kustomize build</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: example-config
        - configMapRef:
            name: backend-properties
        image: docker.io/alpine:latest
        name: example
</code></pre>
