<p>In my <code>kustomization.yaml</code> I have:</p>
<pre class="lang-yaml prettyprint-override"><code>...
secretGenerator:
  - name: db-env
    behavior: create
    envs:
      - my.env
patchesStrategicMerge:
  - app.yaml
</code></pre>
<p>And then in my <code>app.yaml</code> (the patch) I have:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deployment
spec:
  template:
    spec:
      containers:
        - name: server
          envFrom:
            - secretRef:
                name: db-env
</code></pre>
<p>When I try build this via <code>kustomize build k8s/development</code> I get back out:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
...
    spec:
      containers:
      - envFrom:
        - secretRef:
            name: db-env
        name: server
</code></pre>
<p>When it should be:</p>
<pre class="lang-yaml prettyprint-override"><code>      - envFrom:
        - secretRef:
            name: db-env-4g95hhmhfc
</code></pre>
<p>How do I get the <code>secretGenerator</code> name hashing to apply to <code>patchesStrategicMerge</code> too?</p>
<p>Or alternatively, what's the proper way to inject some environment vars into a deployment for a specific overlay?</p>
<p>This for development.</p>
<hr />
<p>My file structure is like:</p>
<pre><code>❯ tree k8s
k8s
├── base
│   ├── app.yaml
│   └── kustomization.yaml
├── development
│   ├── app.yaml
│   ├── golinks.sql
│   ├── kustomization.yaml
│   ├── mariadb.yaml
│   ├── my.cnf
│   └── my.env
└── production
    ├── ingress.yaml
    └── kustomization.yaml
</code></pre>
<p>Where <code>base/kustomization.yaml</code> is:</p>
<pre class="lang-yaml prettyprint-override"><code>namespace: go-mpen
resources:
- app.yaml
images:
- name: server
  newName: reg/proj/server
</code></pre>
<p>and <code>development/kustomization.yaml</code> is:</p>
<pre class="lang-yaml prettyprint-override"><code>resources:
  - ../base
  - mariadb.yaml
configMapGenerator:
  - name: mariadb-config
    files:
      - my.cnf
  - name: initdb-config
    files:
      - golinks.sql  # TODO: can we mount this w/out a config file?
secretGenerator:
  - name: db-env
    behavior: create
    envs:
      - my.env
patchesStrategicMerge:
  - app.yaml
</code></pre>

<p>This works fine for me with <code>kustomize v3.8.4</code>.  Can you please check your version and if <code>disableNameSuffixHash</code> is not perhaps set to you true.</p>
<p>Here are the manifests used by me to test this:</p>
<pre><code>➜  app.yaml  deployment.yaml  kustomization.yaml   my.env
</code></pre>
<p>app.yaml</p>
<pre><code>kind: Deployment
metadata:
  name: app-deployment
spec:
  template:
    spec:
      containers:
        - name: server
          envFrom:
            - secretRef:
                name: db-env
</code></pre>
<p>deplyoment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-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
</code></pre>
<p>and my kustomization.yaml</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

secretGenerator:
  - name: db-env
    behavior: create
    envs:
      - my.env
patchesStrategicMerge:
  - app.yaml

resources: 
  - deployment.yaml 
</code></pre>
<p>And here is the result:</p>
<pre><code>apiVersion: v1
data:
  ASD: MTIz
kind: Secret
metadata:
  name: db-env-f5tt4gtd7d
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: app-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.14.2
        name: nginx
        ports:
        - containerPort: 80
      - envFrom:
        - secretRef:
            name: db-env-f5tt4gtd7d
        name: server
</code></pre>
