<p>I have a kustomize layout something like this:</p>
<pre><code>├──release
│  ├──VariantA
│  │  └──kustomization.yaml
│  │     cluster_a.yaml
|  └──VariantB
│     └──kustomization.yaml
│        cluster_b.yaml
└──test
   ├──TestVariantA
   │  └──kustomization.yaml; resources=[VariantA]
   │     common_cluster_patch.yaml
   └──TestVariantB
      └──kustomization.yaml; resources=[VariantB]
         common_cluster_patch.yaml
</code></pre>
<p>My issue is the duplication of <code>common_cluster_patch.yaml</code>. It is a common patch which I need to apply to the the different base cluster objects. I would prefer not to have to maintain identical copies of it for each test variant.</p>
<p>The 2 unsuccessful solutions I tried are:</p>
<p><strong>A common patch resource</strong></p>
<pre><code>├──release
│  ├──VariantA
│  │  └──kustomization.yaml
│  │     cluster_a.yaml
|  └──VariantB
│     └──kustomization.yaml
│        cluster_b.yaml
└──test
   ├──TestVariantA
   │  └──kustomization.yaml; resources=[VariantA, TestPatch]
   ├──TestVariantB
   │  └──kustomization.yaml; resources=[VariantB, TestPatch]
   └──TestPatch
      └──kustomization.yaml
         common_cluster_patch.yaml
</code></pre>
<p>This fails with <code>no matches for Id Cluster...</code>, presumably because TestPatch is trying to patch an object it doesn't contain.</p>
<p><strong>A common patch directory</strong></p>
<pre><code>├──release
│  ├──VariantA
│  │  └──kustomization.yaml
│  │     cluster_a.yaml
|  └──VariantB
│     └──kustomization.yaml
│        cluster_b.yaml
└──test
   ├──TestVariantA
   │  └──kustomization.yaml; resources=[VariantA]; patches=[../TestPatch/common_cluster_patch.yaml]
   ├──TestVariantB
   │  └──kustomization.yaml; resources=[VariantB]; patches=[../TestPatch/common_cluster_patch.yaml]
   └──TestPatch
      └──common_cluster_patch.yaml
</code></pre>
<p>This fails with: <code>'/path/to/test/TestPatch/common_cluster_patch.yaml' is not in or below '/path/to/test/TestVariantA'</code>.</p>
<p>I can work round this and successfully generate my templates with <code>kustomize build --load-restrictor LoadRestrictionsNone</code>, but this comes with dire warnings and portents. I am hoping that there is some better way of organising my resources which doesn't require either workarounds or duplication.</p>

Matthew Booth
<p>Thanks to criztovyl for this answer! The solution is <a href="https://kubectl.docs.kubernetes.io/guides/config_management/components/" rel="nofollow noreferrer">kustomize components</a>. Components are currently only defined in <code>kustomize.config.k8s.io/v1alpha1</code> and the <a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/components/" rel="nofollow noreferrer">reference documentation</a> is a stub, but they are included in current release versions of kustomize.</p>
<p>My solution now looks like:</p>
<pre><code>├──release
│  ├──VariantA
│  │  └──kustomization.yaml
│  │     cluster_a.yaml
|  └──VariantB
│     └──kustomization.yaml
│        cluster_b.yaml
└──test
   ├──TestVariantA
   │  └──kustomization.yaml; resources=[VariantA]; components=[../TestCommon]
   ├──TestVariantB
   │  └──kustomization.yaml; resources=[VariantB]; components=[../TestCommon]
   └──TestCommon
      └──kustomization.yaml; patches=[common_cluster_patch.yaml]
         common_cluster_patch.yaml
</code></pre>
<p>where <code>test/TestCommon/kustomization.yaml</code> has the header:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
</code></pre>
<p>The crucial difference between a component and a resource is that a component is applied after other processing. This means it can patch an object in the resource which included it.</p>
