Skip to content

Instantly share code, notes, and snippets.

@clcollins
Created January 27, 2025 23:09
Show Gist options
  • Save clcollins/1cec9c6b0f0fdd7807b8052dbed7c3b0 to your computer and use it in GitHub Desktop.
Save clcollins/1cec9c6b0f0fdd7807b8052dbed7c3b0 to your computer and use it in GitHub Desktop.
OLM Reinstall
#!/usr/bin/env bash
set -euxo pipefail
set -o nounset
NAMESPACE="${1}"
OPERATOR="${2}"
# Look for a CSV, then perform the reinstall if found. If you want to _always_ reinstall, remove this check and just keep the logic inside the "if"
CSV_FOUND=$(oc -n "$NAMESPACE" get clusterserviceversions.operators.coreos.com -o name | grep "$OPERATOR")
if [[ ! -z "$CSV_FOUND" ]]; then
# The OLM dance
# delete all CSVs
oc get clusterserviceversions.operators.coreos.com -n $NAMESPACE | grep $OPERATOR | awk '{print $1}' | xargs oc delete clusterserviceversions.operators.coreos.com -n $NAMESPACE
# delete all installplans
oc get installplans.operators.coreos.com -n $NAMESPACE | grep $OPERATOR | awk '{print $1}' | xargs oc delete installplan.operators.coreos.com -n $NAMESPACE
# get subscription
oc get subscription.operators.coreos.com -n $NAMESPACE $OPERATOR -o json | jq 'del(.status) | del(.metadata.creationTimestamp) | del(.metadata.generation) | del(.metadata.resourceVersion) | del(.metadata.uid)' > /tmp/sub.json
# delete subscription
oc delete subscription.operators.coreos.com -n $NAMESPACE $OPERATOR
# create subscription using the following json
ocm backplane elevate -n -- create -f /tmp/sub.json
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment