Bartosz Bierkowski - Low dose cloud

OpenShift CLI morsels: updating objects non-interactively

Recently, when I tried to answer the question: Openshift: how to edit scc non-interactively? I learned about nice feature of oc patch . It allows to change single values in OpenShift objects.

Patching the resources

For this scenario, let’s say we have a deployment config called paprika. Standard way to update it is to run oc edit dc paprika  and change fields. That works only until it is not a repeatable task or something that needs to be done often.

Changing single value

Using oc patch dc paprika --type=json -p ...  you can easily automate simple tasks. Setting the rolling update timeout using this approach looks like this:

The patch is an array of objects with the following fields:

  • op – one of the operations: add, remove, replace, copy, move, test
  • from – source path used in copy and move operations
  • path – destination path of the operation
  • value – new value to be added/set or tested value

More examples

Check if first trigger is imageChange trigger

And disable the trigger only if the first trigger is ‘ImageChange’ one.

Second trigger is ‘ConfigChange’ one, so the test fails and patch is not applied

Documentation

The OpenShift documentation about this feature practically doesn’t exist. One example can be found at kubectl patch docs page

You can learn more about json patch syntax at http://jsonpatch.com

Environment

The commands were executed using minishift and the following client/server versions of OpenShift.

Client:
oc v1.5.0-alpha.2+e4b43ee
client kubernetes v1.5.2+43a9be4
Server:
openshift v1.3.1
server kubernetes v1.3.0+52492b4

Newsletter

Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.

As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.

Did you like the article?
Join the newsletter to receive notifications about new articles.
I respect your privacy.