Openshift/OKD template if/else condition Openshift/OKD template if/else condition kubernetes kubernetes

Openshift/OKD template if/else condition


You can't do this kind of conditional processing at the template level.

But, to achieve your desired outcome, you can do one of 2 things.

Option 1Pass all the parameters required for the condition to process at the template level, like MQTT-PORTand 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.

Option 2If 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 DRY principle.

Update

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 repository 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 here.