Created
January 21, 2022 03:43
Uninstall KubeVirt the hard way
This file contains 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
#!/bin/bash | |
# Try to clean everything created by kubevirt | |
KC=kubectl | |
# Take out anything added by KubeVirt that lives in a namespace | |
NSRES=$($KC api-resources --namespaced=true | awk '/kubevirt.io/ {print $1}'| tr -s ' ' ',') | |
$KC delete $res --all-namespaces --all --now=true --wait=false | |
# Take out any cluster-wide KubeVirt resources | |
UNNSRES=$($KC api-resources --namespaced=false | awk '/kubevirt.io/ {print $1}'| tr -s ' ' ',') | |
LIST=$($KC get $UNNSRES -o name) | |
if [ -n "${LIST}" ] | |
then | |
${KC} delete $LIST | |
fi | |
# Now go through by label for all resources | |
UNNSRES=$($KC api-resources --namespaced=false | awk '{print $1}') | |
for res in $UNNSRES | |
do | |
LIST=$(${KC} get $res -l app.kubernetes.io/managed-by=virt-operator -o name) | |
if [ -n "${LIST}" ] | |
then | |
${KC} delete $LIST --now=true --wait=false | |
fi | |
done | |
NSRES=$($KC api-resources --namespaced=true | awk '{print $1}') | |
NAMESPACES=$($KC get ns -o name | awk -F/ '{print $2}') | |
for ns in $NAMESPACES | |
do | |
for res in $NSRES | |
do | |
LIST=$($KC -n $ns get $res -l app.kubernetes.io/managed-by=virt-operator -o name) | |
if [ -n "${LIST}" ] | |
then | |
${KC} -n $res delete $LIST --now=true --wait=false | |
fi | |
done | |
done | |
# Say I told you so! | |
$KC -n kubevirt patch kubevirt kubevirt -p '{"metadata":{"finalizers":null}}' --type=merge | |
$KC delete ns kubevirt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment