Add a file into an existing Openshift configMap Add a file into an existing Openshift configMap jenkins jenkins

Add a file into an existing Openshift configMap


I was able to get what I think you want by using json instead of yaml, and using jq with its multiplication operator(*) which, when used with objects, will merge them recursively (split lines for readability):

oc export configmap my-config -o json \  | jq ". * $(oc create configmap my-config --from-file path/to/file.properties --dry-run -o json)" \  | oc apply -f -

While this works fine if you're looking for a one-liner, you could also manually edit the configmap in your text editor with oc edit configmap my-config, or oc replace (with a newly prepared json or yaml file), or by using the web console. It might be possible with oc patch also, but I wasn't able to get that working quickly.


oc patch is your friend:

oc patch cm myconfig -p $(cat patch_file.yaml)

where patch_file.yaml has:

data:  file.properties: |    content of the file here

if file.properties is not in the cm it will be created and merged with the rest of the data, if it is in it will be replaced.