<p>I'm trying to create a template that allows an application to be promoted across several environments. Currently I create a project and then import the template into that, the template creates all the objects needed in the default namespace(the project I manually created), the other projects I need and a cluster role allowing me to promote pods through the environments. The problem is that I also want the template to create objects in the projects that were newly created but this fails with the error message:</p>

<blockquote>
  <p>the namespace of the provided object does not match the namespace sent on the request</p>
</blockquote>

<p>I think this may be an issue with Openshift trying to create the objects at the same time as the projects and it doesn't find the project at the time it tries to create the objects. To fix this I tried using the <code>service.alpha.openshift.io/dependencies</code> annotation but got the same error </p>

<p>Any assistance would be greatly appreciated</p>

<p>According to <a href="https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html" rel="nofollow noreferrer">documentation</a>:</p>

<blockquote>
  <p>If an object definition’s metadata includes a fixed namespace field value, the field will be stripped out of the definition during template instantiation. If the namespace field contains a parameter reference, normal parameter substitution will be performed and the object will be created in whatever namespace the parameter substitution resolved the value to, assuming the user has permission to create objects in that namespace.</p>
</blockquote>

<p>So just specify required namespaces as template's parameters. Usable example:</p>

<pre><code>apiVersion: template.openshift.io/v1
kind: Template
metadata:
  name: yyy
parameters:
- name: ns3
  value: test3
objects:
- apiVersion: v1
  kind: Namespace
  metadata:
    name: ${ns3}
  spec:
    finalizers:
    - kubernetes
- apiVersion: v1
  data:
    key3: value3
  kind: ConfigMap
  metadata:
    namespace: ${ns3}
    name: cm3
</code></pre>
