Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Created October 23, 2019 20:42
Show Gist options
  • Save jovemfelix/f65d2b57938939098c4c8acdbe8b3f38 to your computer and use it in GitHub Desktop.
Save jovemfelix/f65d2b57938939098c4c8acdbe8b3f38 to your computer and use it in GitHub Desktop.
example of handling environment variables using oc patch
## 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}")
@jovemfelix
Copy link
Author

Was very helpefull this link to test the JSON - https://json8.github.io/patch/demos/apply/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment