<p>I have a huge patch file that I want to apply to specific overlays. I usually patch files under overlays as it is supposed to be. But the file is same and I do not want to copy it to each overlay. If I could keep my patch file <code>app-new-manifest.yaml</code> under base and patch it under overlay with a single line in <code>kustomization.yaml</code>, it would be awesome.</p>
<pre><code>├── base
│   ├── app-new-manifest.yaml # I am trying to patch this
│   ├── kustomization.yaml
│   ├── app
│   │   ├── app.yaml
│   │   └── kustomization.yaml
└── overlay
    └── environment1
    │    ├── kustomization.yaml # I want to patch app-new-manifest.yaml in base
    │
    └── environment2
    │    ├── kustomization.yaml # No patch. app.yaml will be as is
    │
    └── environment3
        ├── kustomization.yaml # I want to patch app-new-manifest.yaml in base
</code></pre>
<p>When I'm trying to do so, I get this error:</p>
<pre><code>'/base/app/app-new-manifest.yaml' is not in or below '/overlays/environment1'
</code></pre>
<p>Which means, when you patch, the patch file has to be located under overlay not base. Is there any workaround to do this? Because copying the same file to each environment does not make sense to me.</p>
<p>Any ideas around this will highly be appreciated, thanks!</p>
<p>Edit:</p>
<p>Add /base/app/kustomization.yaml</p>
<pre><code>resources:
  - app.yaml
</code></pre>
<p>Add /overlays/environment1/kustomization.yaml</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../../base/app

patchesStrategicMerge:
  - ../../base/app/app-new-manifest.yaml # Patch new manifest
</code></pre>
<p>kustomize version:</p>
<pre><code>{Version:kustomize/v4.2.0 GitCommit:d53a2ad45d04b0264bcee9e19879437d851cb778 BuildDate:2021-07-01T00:44:28+01:00 GoOs:darwin GoArch:amd64}
</code></pre>

<p>You can't include a file that is outside of you current directory, but you <em>can</em> include another directory that has a <code>kustomize.yaml</code> file. So organize your layout like this:</p>
<pre><code>.
├── base
└── overlay
    ├── patched_based
    ├── environment1
    ├── environment2
    └── environment3
</code></pre>
<p>In <code>overlay/patched_base</code>, place your patch file and a kustomization file like:</p>
<pre><code>resources:
  - ../base

patchesStrategicMerge:
  - app-new-manifest.yaml
</code></pre>
<p>In <code>overlay/environment1</code> and <code>overlay/environment3</code>, you have:</p>
<pre><code>resources:
   - ../patched_base
</code></pre>
<p>Whereas in <code>overlay/environment2</code>, you have:</p>
<pre><code>resources:
  - ../../base
</code></pre>
<p>I think this solves all your requirements:</p>
<ul>
<li>You only need a single instance of the patch</li>
<li>You can choose to use the patch or not from each individual overlay</li>
</ul>
