2020-04-01 13:53:13 +05:30
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
if [ -z $1 ]; then
|
|
|
|
|
# default namespace is openebs when all the custom resources are created
|
|
|
|
|
ZFSPV_NAMESPACE="openebs"
|
|
|
|
|
else
|
|
|
|
|
ZFSPV_NAMESPACE=$1
|
|
|
|
|
fi
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
echo "Fetching ZFS Volumes"
|
|
|
|
|
numVol=`kubectl get zfsvolumes.openebs.io --no-headers -n $ZFSPV_NAMESPACE | wc -l`
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
if [ $numVol -gt 0 ]; then
|
|
|
|
|
echo "Cleaning the ZFS Volumes($numVol)"
|
|
|
|
|
kubectl get zfsvolumes.openebs.io -n $ZFSPV_NAMESPACE -oyaml > volumes.yaml
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
# remove the finalizer from the old CR
|
|
|
|
|
sed -i "/zfs.openebs.io\/finalizer/d" volumes.yaml
|
|
|
|
|
kubectl apply -f volumes.yaml
|
|
|
|
|
|
|
|
|
|
# delete the old CR
|
|
|
|
|
kubectl delete -f volumes.yaml
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# delete the ZFSVolume CRD definition
|
2020-04-01 13:53:13 +05:30
|
|
|
kubectl delete crd zfsvolumes.openebs.io
|
|
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
numAttach=`kubectl get volumeattachment --no-headers | grep zfs.csi.openebs.io | wc -l`
|
|
|
|
|
|
|
|
|
|
if [ $numAttach -gt 0 ]; then
|
|
|
|
|
echo "Cleaning the volumeattachment($numAttach)"
|
|
|
|
|
# delete the volumeattachment object
|
|
|
|
|
kubectl delete volumeattachment --all
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Fetching ZFS Snapshots"
|
|
|
|
|
numSnap=`kubectl get zfssnapshots.openebs.io --no-headers -n $ZFSPV_NAMESPACE | wc -l`
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
if [ $numSnap -gt 0 ]; then
|
|
|
|
|
echo "Cleaning the ZFS Snapshot($numSnap)"
|
|
|
|
|
kubectl get zfssnapshots.openebs.io -n $ZFSPV_NAMESPACE -oyaml > snapshots.yaml
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
# remove the finalizer from the old CR
|
|
|
|
|
sed -i "/zfs.openebs.io\/finalizer/d" snapshots.yaml
|
|
|
|
|
kubectl apply -f snapshots.yaml
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
# delete the old CR
|
|
|
|
|
kubectl delete -f snapshots.yaml
|
|
|
|
|
fi
|
2020-04-01 13:53:13 +05:30
|
|
|
|
2020-04-17 13:59:28 +05:30
|
|
|
# delete the ZFSSnapshot CRD definition
|
2020-04-01 13:53:13 +05:30
|
|
|
kubectl delete crd zfssnapshots.openebs.io
|