<p>Currently I have an OKD/openshift template which exposes port 1883 on a specific container:</p>

<pre><code>ports:
 - name: 1883-tcp
   port: 1883
   containerPort: 1883
   protocol: TCP
   hostPort: ${MQTT-PORT}
</code></pre>

<p>Is it possible to have an if/else clause depending on parameters. For example:</p>

<pre><code>ports:
 - name: 1883-tcp
   port: 1883
   containerPort: 1883
   protocol: TCP
   {{ if ${MQTT-PORT} != 0 }}
   hostPort: ${MQTT-PORT}
   {{ /if }}
</code></pre>

<p>By doing this, I can have the same template in all my environments (e.g.: development/testing/production) but based on the parameters given by creation, some ports are available for debugging or testing without having to forward them each time using the oc command.</p>

<p>You can't do this kind of conditional processing at the template level. </p>

<p>But, to achieve your desired outcome, you can do one of 2 things.</p>

<p><strong>Option 1</strong>
Pass all the parameters required for the condition to process at the template level, like <code>MQTT-PORT</code>and map the correct port number when building your service.
This might be the correct approach as templates are designed to be as logic-less as possible, you do all the decision making at a much lower level.</p>

<p><strong>Option 2</strong>
If you can relax the "same template" constraint, We could have 2 flavors of the same template, one with the specific port and another with the parameterized port. The only issue with this option is to change 2 templates every time you change your app/service specs, which violates the <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow noreferrer">DRY principle</a>.</p>

<p><strong>Update</strong></p>

<p>Using Helm with OpenShift might be the best option here. You can templatize your artifacts using Helm's conditionals and deploy a Helm app to OpenShift. Here's a <a href="https://github.com/sclorg/nodejs-ex/tree/master/helm/nodejs/templates" rel="nofollow noreferrer">repository</a> which has a Helm chart tailored for OpenShift.
Also, you need to point to the right namespace for Tiller to use Helm with OpenShift. You can find more details about it <a href="https://blog.openshift.com/getting-started-helm-openshift/" rel="nofollow noreferrer">here</a>.</p>
