5

I am currently building and deploying an Application with a template using

oc new-app -f ./openshift/template.yaml

I am using a template and not separate Deployment-, Build-, etc. configs because I also want to be able to pass parameters like

oc new-app -f ./openshift/template.yaml --p DATABASE_PW=PW

To my knowledge this is not possible using

oc create -f ./openshift/deploymentconfig.yaml --p SOME_PARAM=TEST

Now I have also integrated this is in a Build Pipeline with Jenkins. My problem is now this. This all works fine on the first deployment, but it will not work for a redployment. I can either just rebuild the app with Jenkins like

oc start-build my-app

But this will cause that changes is my Template will not be considered. I also cannot use new-app as it does not replace existing configs producing an error similar to this

--> Creating resources ...
    error: services "my-app" already exists
    ....
--> Failed

Is there a way to solve this problem? Maybe something like a new-app replace command where all the configs are being replaced? I am currently solving this by killing the app completely using a shell file and then bringing it up again; but that will always cause a downtime of a few minutes which really bothers me.

blong
  • 2,815
  • 8
  • 44
  • 110
relief.melone
  • 3,042
  • 1
  • 28
  • 57
  • 3
    Try ``oc process -f openshift/template.yaml --param DATABASE_PW=PW | oc apply -f -``. – Graham Dumpleton Jan 18 '19 at 08:23
  • Awesome. This is exaclty what I needed. Can be so simple if you know how. I saw it works also for the creation so i wont even need oc new-app anymore. Do you want to write it down as answer or shall I? – relief.melone Jan 18 '19 at 08:44
  • 1
    You can also store your parameters in a file, and then pass the file with `--param-file=`, which is nice when you start accumulating more and more parameters. – Ciaodown Jan 18 '19 at 13:18

2 Answers2

3

As Graham pointed out the best way to solve this is to use

oc process -f openshift/template.yaml -p PARAM1=VALUE1 -p PARAM2=VALUE2

to first fill your template with your parameters. Then pipe the command to oc apply to apply it to the application which will leave you with the following command

oc process -f openshift/template.yaml -p PARAM1=VALUE1 -p PARAM2=VALUE2 | oc apply -f -

This will create or update all your configs. It will also check which configs have been changed.

If you want to start the build directly afterwards use

oc start-build my-app
relief.melone
  • 3,042
  • 1
  • 28
  • 57
  • 1
    Is there a way to skip `oc new-app` and instantiate an application directly with `oc process | oc apply`? – Display Name Jan 23 '20 at 11:37
  • using oc apply on resources that were created via new-app with a template gives the warning message: "oc apply should be used on resource created by either oc create --save-config or oc apply". This makes me think there must be something different in mind for resources created from templates - or that maybe oc create/oc apply are preferred over using oc new-app. – krock Aug 07 '20 at 09:54
0

To update a template parameter in a running pod which was started from a template YAML file (i.e. with oc create -f ./$tmpl_name.yaml):

# delete existing dc (leaving svc & route)
# (here dc and template are named the same: $tmpl_name)
oc delete dc $tmpl_name
    
# update template parameter (notice template was not deleted)
oc process $tmpl_name -p $PARAM_NAME=$PARAM_VALUE | oc create -f -
mirekphd
  • 4,799
  • 3
  • 38
  • 59