Extract the OpenShift Server Version directly from oc version
.
$ current_version=$(oc version | grep 'Server Version' | awk '{print $3}')
4.12.45
Record the currently running console image ref:
$ original_console_image=$(oc adm release info $current_version -o json | jq -r '.references.spec.tags[] | select(.name == "console") | .from.name')
$ echo $original_console_image
quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:b85e538797e969a56c66924130fb71de430a8c988a2922b6a1ff85512c51d88d
Take the console-operator unmanaged:
$ oc patch clusterversions/version --type=json --patch='[{"op": "add", "path": "/spec/overrides", "value":[{"group":"apps", "kind":"Deployment", "name":"console-operator", "namespace":"openshift-console-operator", "unmanaged":true}]}]'
This adds the following override to the CVO:
overrides:
- group: apps
kind: Deployment
name: console-operator
namespace: openshift-console-operator
unmanaged: true
Scale down the console-operator as we will be replacing the image:
$ oc scale -n openshift-console-operator --replicas 0 deployment console-operator
Verify the console operator stops:
$ oc get -n openshift-console-operator pods
No resources found in openshift-console-operator namespace.
Note the image reference from 4.10.39:
$ oc adm release info 4.10.39 --pullspecs | grep -w console
console quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:c50a6a2afe209702475c5fb91d3a8ef2843eb46ec50e7eee57d7a1fcf6c7f557
console-operator quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:99e837391012d43c16fa8a564fedc0e32b9ae82ceaba2f3940ac11b24e9feb36
Save the console image reference in a shell variable:
$ console_image=$(oc adm release info 4.10.39 -o json | jq -r '.references.spec.tags[] | select(.name == "console") | .from.name')
$ echo $console_image
$ quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:c50a6a2afe209702475c5fb91d3a8ef2843eb46ec50e7eee57d7a1fcf6c7f557
Replace the image:
$ oc set image deployment/console console="$console_image" -n openshift-console
Verify that the console pods rollout with the new image:
$ oc get pods -n openshift-console -w
NAME READY STATUS RESTARTS AGE
console-68b95d5d84-9g62g 1/1 Terminating 0 7s
console-694f5848f5-9d5ph 1/1 Running 0 22m
console-694f5848f5-j4xnl 1/1 Terminating 0 22m
console-694f5848f5-s9vcw 0/1 Pending 0 7s
downloads-7fcfbdd4ff-6xhdq 1/1 Running 0 16h
downloads-7fcfbdd4ff-rs57j 1/1 Running 0 16h
Grab the new image ref:
$ oc describe deployment console -n openshift-console | grep 'Image:'
Image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:c50a6a2afe209702475c5fb91d3a8ef2843eb46ec50e7eee57d7a1fcf6c7f557
Which should match $console_image
:
$ echo $console_image
quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:c50a6a2afe209702475c5fb91d3a8ef2843eb46ec50e7eee57d7a1fcf6c7f557
Remove the CVO override
$ oc patch clusterversions/version --type=json --patch='[{"op": "replace", "path": "/spec/overrides", "value":[]}]'
Scale out the console-operator:
$ oc scale -n openshift-console-operator --replicas 1 deployment console-operator
deployment.apps/console-operator scaled
Set the console image back to $original_console_image
:
$ oc set image deployment/console console="$original_console_image" -n openshift-console
Force a rollout of the console pods so that we can verify the image reference:
$ oc rollout restart deployment console -n openshift-console
$ oc get pods -n openshift-console
NAME READY STATUS RESTARTS AGE
console-694f5848f5-2fxbz 1/1 Running 0 53s
console-694f5848f5-ltw8r 1/1 Running 0 53s
downloads-7fcfbdd4ff-6xhdq 1/1 Running 0 17h
downloads-7fcfbdd4ff-rs57j 1/1 Running 0 17h
$ oc describe deployment console -n openshift-console | grep 'Image:'
Image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:b85e538797e969a56c66924130fb71de430a8c988a2922b6a1ff85512c51d88d
$ echo $original_console_image
quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:b85e538797e969a56c66924130fb71de430a8c988a2922b6a1ff85512c51d88d
$ oc describe deployment console -n openshift-console | grep 'Image:' | awk '{print $2}' | grep -q "$original_console_image" && echo "SUCCESS: console image is restored" || echo "****FAILED****"