<p>I have a kustomize base that I'd like to re-use without editing it. Unfortunately, it creates a namespace I don't want to create. I'd like to simply remove that resource from consideration when compiling the manifests and add a resource for mine since I can't patch a namespace to change the name.</p>
<p>Can this be done? How?</p>

<p>You can omit the specific resource by using a delete directive of <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md#delete-directive" rel="noreferrer">Strategic Merge Patch</a> like this.</p>
<p>Folder structure</p>
<pre><code>$ tree .
.
├── base
│   ├── kustomization.yaml
│   └── namespace.yaml
└── overlays
    ├── dev
    │   └── kustomization.yaml
    └── prod
        ├── delete-ns-b.yaml
        └── kustomization.yaml
</code></pre>
<p>File content</p>
<pre><code>$ cat base/kustomization.yaml
resources:
  - namespace.yaml

$  cat base/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: ns-a
---
apiVersion: v1
kind: Namespace
metadata:
  name: ns-b

$ cat overlays/dev/kustomization.yaml
bases:
  - ../../base

$ cat overlays/prod/delete-ns-b.yaml
$patch: delete
apiVersion: v1
kind: Namespace
metadata:
  name: ns-b

$ cat overlays/prod/kustomization.yaml
bases:
  - ../../base
patchesStrategicMerge:
  - delete-ns-b.yaml
</code></pre>
<p>Behavior of kustomize</p>
<pre><code>$ kustomize build overlays/dev
apiVersion: v1
kind: Namespace
metadata:
  name: ns-a
---
apiVersion: v1
kind: Namespace
metadata:
  name: ns-b

$ kustomize build overlays/prod
apiVersion: v1
kind: Namespace
metadata:
  name: ns-a
</code></pre>
<p>In this case, we have two namespaces in the base folder. In dev, kustomize produces 2 namespaces because there is no patch. But, in prod, kustomize produces only one namespace because delete patch deletes namespace ns-b.</p>
