From 8a9ac43ab58120277be67d66b9b2889b88d8436a Mon Sep 17 00:00:00 2001 From: Pawan Prakash Sharma Date: Wed, 1 Apr 2020 13:53:13 +0530 Subject: [PATCH] feat(crd): scripts to help migrating to new CRDs (#73) The CRDs have changed from being under openebs.io to zfs.openebs.io. The scripts in this commit and the following steps will help users migrate existing CRDs to new CRDs and clean up older CRDs. # upgrade to new CRD 1. apply the crd yaml `$ kubectl apply -f upgrade/crd.yaml` 2. run upgrade.sh `$ upgrade/upgrade.sh` 3. upgrade the driver to v0.6 `$ kubectl apply -f https://github.com/openebs/zfs-localpv/blob/v0.6.x/deploy/zfs-operator.yaml` 4. if everything looks good run the cleanup.sh, it will clean old CRs and delete the CRD `$ upgrade/cleanup.sh` Signed-off-by: Pawan --- upgrade/cleanup.sh | 28 +++++++++++++++++++ upgrade/crd.yaml | 68 ++++++++++++++++++++++++++++++++++++++++++++++ upgrade/upgrade.sh | 28 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 upgrade/cleanup.sh create mode 100644 upgrade/crd.yaml create mode 100644 upgrade/upgrade.sh diff --git a/upgrade/cleanup.sh b/upgrade/cleanup.sh new file mode 100644 index 00000000..afdb901a --- /dev/null +++ b/upgrade/cleanup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +kubectl get zfsvolumes.openebs.io -n openebs -oyaml > 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 old CR +kubectl delete -f volumes.yaml + +# delete the CRD definition +kubectl delete crd zfsvolumes.openebs.io + + +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 + +# delete the old CR +kubectl delete -f snapshots.yaml + +# delete the CRD definition +kubectl delete crd zfssnapshots.openebs.io diff --git a/upgrade/crd.yaml b/upgrade/crd.yaml new file mode 100644 index 00000000..ea42ca02 --- /dev/null +++ b/upgrade/crd.yaml @@ -0,0 +1,68 @@ +############################################## +########### ############ +########### ZFSVolume CRD ############ +########### ############ +############################################## +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: zfsvolumes.zfs.openebs.io +spec: + group: zfs.openebs.io + version: v1alpha1 + scope: Namespaced + names: + plural: zfsvolumes + singular: zfsvolume + kind: ZFSVolume + shortNames: + - zfsvol + - zv + additionalPrinterColumns: + - JSONPath: .spec.poolName + name: ZPool + description: ZFS Pool where the volume is created + type: string + - JSONPath: .spec.ownerNodeID + name: Node + description: Node where the volume is created + type: string + - JSONPath: .spec.capacity + name: Size + description: Size of the volume + type: string + - JSONPath: .spec.volblocksize + name: volblocksize + description: volblocksize for the created zvol + type: string + - JSONPath: .spec.recordsize + name: recordsize + description: recordsize for the created zfs dataset + type: string + - JSONPath: .spec.fsType + name: Filesystem + description: filesystem created on the volume + type: string +--- +############################################## +########### ############ +########### Snapshot CRD ############ +########### ############ +############################################## + +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: zfssnapshots.zfs.openebs.io +spec: + group: zfs.openebs.io + version: v1alpha1 + scope: Namespaced + names: + plural: zfssnapshots + singular: zfssnapshot + kind: ZFSSnapshot + shortNames: + - zfssnapshot + - zfssnap +--- diff --git a/upgrade/upgrade.sh b/upgrade/upgrade.sh new file mode 100644 index 00000000..737508d9 --- /dev/null +++ b/upgrade/upgrade.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +# ZFSVolumes: create the new CR with apiVersion as zfs.openebs.io and kind as Volume + +kubectl get zfsvolumes.openebs.io -n openebs -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 + +rm volumes.yaml + + +# 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 + + +# 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