Skip to content

Commit

Permalink
improving upgrade script
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Apr 20, 2020
1 parent 438eae5 commit 9a0b9a0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 33 deletions.
10 changes: 7 additions & 3 deletions upgrade/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From zfs-driver:v0.6 version ZFS-LocalPV related CRs are now grouped together in its own group called `zfs.openebs.io`. Here steps are mentioned for how to upgrade for refactoring the CRDs.
From zfs-driver:v0.6 version ZFS-LocalPV related CRs are now grouped together in its own group called `zfs.openebs.io`. Here steps are mentioned for how to upgrade for refactoring the CRDs. Please do not provision/deprovision any volume during the upgrade.

steps to upgrade:-

Expand All @@ -21,7 +21,9 @@ zfsvolume.zfs.openebs.io/pvc-82368c44-eee8-47ee-85a6-633a8023faa8 created
zfssnapshot.zfs.openebs.io/snapshot-dc61a056-f495-482b-8e6e-e7ddc4c13f47 created
zfssnapshot.zfs.openebs.io/snapshot-f9db91ea-529e-4dac-b2b8-ead045c612da created
```
`
Please note that if you have modified the OPENEBS_NAMESPACE env in the driver's deployment to other namespace. Then you have to pass the namespace as an argument to the upgrade.sh script `sh upgrade/upgrash.sh [namespace]`.


3. upgrade the driver to v0.6

```
Expand Down Expand Up @@ -55,4 +57,6 @@ zfssnapshot.openebs.io/snapshot-f9db91ea-529e-4dac-b2b8-ead045c612da configured
zfssnapshot.openebs.io "snapshot-dc61a056-f495-482b-8e6e-e7ddc4c13f47" deleted
zfssnapshot.openebs.io "snapshot-f9db91ea-529e-4dac-b2b8-ead045c612da" deleted
customresourcedefinition.apiextensions.k8s.io "zfssnapshots.openebs.io" deleted
```
```

Please note that if you have modified the OPENEBS_NAMESPACE env in the driver's deployment to other namespace. Then you have to pass the namespace as an argument to the cleanup.sh script `sh upgrade/cleanup.sh [namespace]`.
47 changes: 31 additions & 16 deletions upgrade/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@

set -e

kubectl get zfsvolumes.openebs.io -n openebs -oyaml > volumes.yaml
numVol=`kubectl get zfsvolumes.openebs.io -n openebs | wc -l`

# remove the finalizer from the old CR
sed -i "/zfs.openebs.io\/finalizer/d" volumes.yaml
kubectl apply -f volumes.yaml
if [ $numVol -gt 1 ]; then
echo "Cleaning the ZFS Volumes(`expr $numVol - 1`)"
kubectl get zfsvolumes.openebs.io -n openebs -oyaml > volumes.yaml

# delete the old CR
kubectl delete -f volumes.yaml
# remove the finalizer from the old CR
sed -i "/zfs.openebs.io\/finalizer/d" volumes.yaml
kubectl apply -f volumes.yaml

# delete the CRD definition
# delete the old CR
kubectl delete -f volumes.yaml
fi

# delete the ZFSVolume CRD definition
kubectl delete crd zfsvolumes.openebs.io

# delete the volumeattachment object
kubectl delete volumeattachment --all
numAttach=`kubectl get volumeattachment | grep zfs.csi.openebs.io | wc -l`

if [ $numAttach -gt 1 ]; then
echo "Cleaning the volumeattachment(`expr $numAttach - 1`)"
# delete the volumeattachment object
kubectl delete volumeattachment --all
fi

numSnap=`kubectl get zfssnapshots.openebs.io -n openebs | wc -l`

kubectl get zfssnapshots.openebs.io -n openebs -oyaml > snapshots.yaml
if [ $numSnap -gt 1 ]; then
echo "Cleaning the ZFS Snapshot(`expr $numSnap - 1`)"
kubectl get zfssnapshots.openebs.io -n openebs -oyaml > snapshots.yaml

# remove the finalizer from the old CR
sed -i "/zfs.openebs.io\/finalizer/d" snapshots.yaml
kubectl apply -f snapshots.yaml
# remove the finalizer from the old CR
sed -i "/zfs.openebs.io\/finalizer/d" snapshots.yaml
kubectl apply -f snapshots.yaml

# delete the old CR
kubectl delete -f snapshots.yaml
# delete the old CR
kubectl delete -f snapshots.yaml
fi

# delete the CRD definition
# delete the ZFSSnapshot CRD definition
kubectl delete crd zfssnapshots.openebs.io
43 changes: 29 additions & 14 deletions upgrade/upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
#!/bin/bash

# do not provision/deprovision anything while running the upgrade script.

set -e

# ZFSVolumes: create the new CR with apiVersion as zfs.openebs.io and kind as Volume
if [ -z $1 ]; then
# default namespace is openebs when all the custom resources are created
ZFSPV_NAMESPACE="openebs"
else
ZFSPV_NAMESPACE=$1
fi

numVol=`kubectl get zfsvolumes.openebs.io -n openebs | wc -l`

kubectl get zfsvolumes.openebs.io -n openebs -oyaml > volumes.yaml
if [ $numVol -gt 1 ]; then
# ZFSVolumes: create the new CR with apiVersion as zfs.openebs.io and kind as Volume

kubectl get zfsvolumes.openebs.io -n $ZFSPV_NAMESPACE -oyaml > volumes.yaml

# update the group name to zfs.openebs.io
sed -i "s/apiVersion: openebs.io/apiVersion: zfs.openebs.io/g" volumes.yaml
# create the new CR
kubectl apply -f volumes.yaml
# update the group name to zfs.openebs.io
sed -i "s/apiVersion: openebs.io/apiVersion: zfs.openebs.io/g" volumes.yaml
# create the new CR
kubectl apply -f volumes.yaml

rm volumes.yaml
rm volumes.yaml
fi

numSnap=`kubectl get zfssnapshots.openebs.io -n openebs | wc -l`

# ZFSSnapshots: create the new CR with apiVersion as zfs.openebs.io and kind as Snapshot
if [ $numSnap -gt 1 ]; then
# ZFSSnapshots: create the new CR with apiVersion as zfs.openebs.io and kind as Snapshot

kubectl get zfssnapshots.openebs.io -n openebs -oyaml > snapshots.yaml
kubectl get zfssnapshots.openebs.io -n openebs -oyaml > snapshots.yaml


# update the group name to zfs.openebs.io
sed -i "s/apiVersion: openebs.io/apiVersion: zfs.openebs.io/g" snapshots.yaml
# create the new CR
kubectl apply -f snapshots.yaml
# update the group name to zfs.openebs.io
sed -i "s/apiVersion: openebs.io/apiVersion: zfs.openebs.io/g" snapshots.yaml
# create the new CR
kubectl apply -f snapshots.yaml

rm snapshots.yaml
rm snapshots.yaml
fi

0 comments on commit 9a0b9a0

Please sign in to comment.