Created
October 23, 2019 20:42
-
-
Save jovemfelix/f65d2b57938939098c4c8acdbe8b3f38 to your computer and use it in GitHub Desktop.
example of handling environment variables using oc patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## SET variable with the name of dc that you want to change | |
PROJETO=xxxx | |
# If you need a replacement a suggest you remove and them add | |
### to remove you can do this | |
oc set env dc/${PROJETO} KUBERNETES_NAMESPACE- | |
## add the deployment config with new item | |
oc patch dc/${PROJETO} --type=json --patch ' | |
[ | |
{ | |
"op": "add", | |
"path": "/spec/template/spec/containers/0/env/-", | |
"value": { | |
"name": "KUBERNETES_NAMESPACE", | |
"valueFrom": { | |
"fieldRef": { | |
"fieldPath": "metadata.namespace" | |
} | |
} | |
} | |
} | |
] | |
' | |
## GET the value updated | |
KUBERNETES_NAMESPACE=$(oc get dc/${PROJETO} -o=jsonpath="{.spec.template.spec.containers[0].env[?(@.name=='KUBERNETES_NAMESPACE')].value}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was very helpefull this link to test the JSON - https://json8.github.io/patch/demos/apply/