Reputation: 5
I am trying to create a simple automation to replace my config map content in OpenShift from the current one to an edited yaml file, I have tried many oc commands and failed, I was wondering if any one had an idea of how to do this.
Just to make u understand:
I'm usingoc get congifmap <configmap name>
to get the current configmap from my project,
Then I am using python to make my changes to the configmap data.
then I want to change the current config map to the new edited one.
I tried edit, apply, change but they all failed.
Would appreciate the help :)
Upvotes: 0
Views: 5698
Reputation: 2977
There is an"oc"
command for such use case:oc patch
With"oc patch"
you can edit, replace, add, remove parts of any OCP object
If you google "oc patch" you'll find many example on the net
Official OCP v4.7 oc patch doc
Tons of examples here
OC patch "man" page
Other examples
Upvotes: 1
Reputation: 852
You just need to work with "inputs" and "outputs".
Imagine a lighttpd.conf
:
server.modules = (
"mod_scgi",
"mod_compress",
"mod_accesslog"
)
oc create cm lighttpd --from-file lighttpd.conf
So, as a example, let's change the mod_scgi to mod_fastcgi. So I wrote this script:
import fileinput
for line in fileinput.input():
if 'mod_scgi' in line:
print(line.replace('scgi', 'fastcgi').rstrip())
else:
print(line.rstrip())
So, to change the configMap
, update it's value and apply again:
oc get cm -o yaml | python modify.py | oc apply -f -
get -o yaml
prints all information on screenmodify.py
modify.py
change and print the lines as they are read from standard inputoc
oc apply -f -
reads from standard input and applyUpvotes: 0