<p>In the following scenario I have my containers defined in ../base/.</p>

<p>In this /dev/ directory I want to start all the deployments and statefulsets in namespace dev.  </p>

<p>The rub is that I also want to run the local-path-storage CSI in the local-path-storage namespace.  kustomize will override it and create it in the "dev" namespace.</p>

<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: dev
bases:
  - ../base    
resources:
  - local-path-storage.yaml
</code></pre>

<p>How can I undo the namespace override for just local-path-storage.yaml?</p>

Dan Garthwaite
<p>It is possible since kustomize 4.5.6 by adding a namespaceTransformer. You want to set the field <code>unsetOnly</code> to <code>true</code>.</p>
<p>Here is an example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
 - ../base    
resources:
 - local-path-storage.yaml
transformers:
  - |-
    apiVersion: builtin
    kind: NamespaceTransformer
    metadata:
      name: notImportantHere
      namespace: dev
    unsetOnly: true
</code></pre>
<p>This should set the namespace to dev for all resources that DO NOT have a namespace set.</p>
<p>Link to namespaceTransformer spec: <a href="https://kubectl.docs.kubernetes.io/references/kustomize/builtins/#_namespacetransformer" rel="noreferrer">https://kubectl.docs.kubernetes.io/references/kustomize/builtins/#_namespacetransformer</a>_</p>
