<p>I'm having difficulty trying to get kustomize to replace contents of an item in a list.</p>
<p>My kustomize file</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - resource.yaml

patches:
  - patch.yaml

</code></pre>
<p>My patch.yaml file</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service
spec:
  template:
    spec:
      initContainers:
        - name: web-service-migration
          env:
            - name: PG_DATABASE
              value: web-pgdb


</code></pre>
<p>My resource.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service
spec:
  template:
    spec:
      initContainers:
        - name: web-service-migration
          env:
            - name: PG_DATABASE
              valueFrom:
                secretKeyRef:
                  name: web-pgdb
                  key: database


</code></pre>
<p>kustomize build returns</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service
spec:
  template:
    spec:
      initContainers:
      - env:
        - name: PG_DATABASE
          value: web-pgdb
          valueFrom:
            secretKeyRef:
              key: database
              name: web-pgdb
        name: web-service-migration
</code></pre>
<p>what i want kustomize build to return</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service
spec:
  template:
    spec:
      initContainers:
      - env:
        - name: PG_DATABASE
          value: web-pgdb
        name: web-service-migration
</code></pre>

<p>If I remember correctly patches in kustomize by default uses strategic merge, so you need to nullify <code>valueFrom</code>, so your patch should look like:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service
spec:
  template:
    spec:
      initContainers:
        - name: web-service-migration
          env:
            - name: PG_DATABASE
              value: web-pgdb
              valueFrom: null 
</code></pre>
<p>More details about strategic merge patch and how to delete maps: <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md#maps" rel="noreferrer">https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md#maps</a></p>
