Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LalatenduMohanty/9599c28e7abd7985eda8b1ae79105271 to your computer and use it in GitHub Desktop.
Save LalatenduMohanty/9599c28e7abd7985eda8b1ae79105271 to your computer and use it in GitHub Desktop.
Hotswap CVO in a running cluster
#!/bin/bash
set -eu
root="$(dirname "${BASH_SOURCE[0]}")/.."
customCvoPullspec=quay.io/petr-muller/cluster-version-operator:"$(git branch --show-current)"
payload="$(oc get -n openshift-cluster-version clusterversion version -o jsonpath='{.status.desired.image}')"
podman pull "$payload"
dockerfile="$(mktemp)"
cp "$root/Dockerfile" "$dockerfile"
sed -i 's|registry.ci.openshift.org/openshift/origin-v4.0:base|'"$payload"'|' "$dockerfile"
sed -i '\|COPY install /manifests|d' "$dockerfile"
sed -i '\|COPY vendor.*|d' "$dockerfile"
sed -i '\|COPY bootstrap.*|d' "$dockerfile"
podman build "$root" -f "$dockerfile" -t "$customCvoPullspec"
podman push "$customCvoPullspec"
digestPullspec="$(skopeo inspect --format='{{.Name}}@{{.Digest}}' docker://"$customCvoPullspec")"
imagePatch='{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"'"$digestPullspec"'"}'
releaseImageArgPatch='{"op":"replace","path":"/spec/template/spec/containers/0/args/1","value":"--release-image='"$digestPullspec"'"}'
oc patch -n openshift-cluster-version deployment cluster-version-operator --type json --patch="[$imagePatch,$releaseImageArgPatch]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment