zfs-localpv/pkg/driver/controller.go

661 lines
18 KiB
Go
Raw Normal View History

/*
Copyright © 2019 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package driver
import (
"fmt"
"strconv"
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
"strings"
"time"
"github.com/Sirupsen/logrus"
"github.com/container-storage-interface/spec/lib/go/csi"
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
"github.com/openebs/zfs-localpv/pkg/builder/snapbuilder"
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
errors "github.com/openebs/zfs-localpv/pkg/common/errors"
"github.com/openebs/zfs-localpv/pkg/common/helpers"
csipayload "github.com/openebs/zfs-localpv/pkg/response"
analytics "github.com/openebs/zfs-localpv/pkg/usage"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// controller is the server implementation
// for CSI Controller
type controller struct {
driver *CSIDriver
capabilities []*csi.ControllerServiceCapability
}
// NewController returns a new instance
// of CSI controller
func NewController(d *CSIDriver) csi.ControllerServer {
return &controller{
driver: d,
capabilities: newControllerCapabilities(),
}
}
// SupportedVolumeCapabilityAccessModes contains the list of supported access
// modes for the volume
var SupportedVolumeCapabilityAccessModes = []*csi.VolumeCapability_AccessMode{
&csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
}
// sendEventOrIgnore sends anonymous local-pv provision/delete events
func sendEventOrIgnore(pvName, capacity, stgType, method string) {
if zfs.GoogleAnalyticsEnabled == "true" {
analytics.New().Build().ApplicationBuilder().
SetVolumeType(stgType, method).
SetDocumentTitle(pvName).
SetLabel(analytics.EventLabelCapacity).
SetReplicaCount(analytics.LocalPVReplicaCount, method).
SetCategory(method).
SetVolumeCapacity(capacity).Send()
}
}
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
volName := req.GetName()
size := req.GetCapacityRange().RequiredBytes
// parameter keys may be mistyped from the CRD specification when declaring
// the storageclass, which kubectl validation will not catch. Because ZFS
// parameter keys (not values!) are all lowercase, keys may safely be forced
// to the lower case.
originalParams := req.GetParameters()
parameters := helpers.GetCaseInsensitiveMap(&originalParams)
rs := parameters["recordsize"]
bs := parameters["volblocksize"]
compression := parameters["compression"]
dedup := parameters["dedup"]
encr := parameters["encryption"]
kf := parameters["keyformat"]
kl := parameters["keylocation"]
pool := parameters["poolname"]
tp := parameters["thinprovision"]
schld := parameters["scheduler"]
fstype := parameters["fstype"]
vtype := zfs.GetVolumeType(fstype)
feat(ZFSPV): volume count based scheduler for ZFSPV (#8) This is an initial scheduler implementation for ZFS Local PV. * adding scheduler as a configurable option * adding volumeWeightedScheduler as scheduling logic The volumeWeightedScheduler will go through all the nodes as per topology information and it will pick the node which has less volume provisioned in the given pool. lets say there are 2 nodes node1 and node2 with below pool configuration :- ``` node1 | |-----> pool1 | | | |------> pvc1 | |------> pvc2 |-----> pool2 |------> pvc3 node2 | |-----> pool1 | | | |------> pvc4 |-----> pool2 |------> pvc5 |------> pvc6 ``` So if application is using pool1 as shown in the below storage class, then ZFS driver will schedule it on node2 as it has one volume as compared to node1 which has 2 volumes in pool1. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool1" ``` So if application is using pool2 as shown in the below storage class, then ZFS driver will schedule it on node1 as it has one volume only as compared node2 which has 2 volumes in pool2. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool2" ``` In case of same number of volumes on all the nodes for the given pool, it can pick any node and schedule the PV on that. Signed-off-by: Pawan <pawan@mayadata.io>
2019-11-06 21:20:49 +05:30
selected := scheduler(req.AccessibilityRequirements, schld, pool)
if len(selected) == 0 {
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
return "", status.Error(codes.Internal, "scheduler failed")
feat(ZFSPV): volume count based scheduler for ZFSPV (#8) This is an initial scheduler implementation for ZFS Local PV. * adding scheduler as a configurable option * adding volumeWeightedScheduler as scheduling logic The volumeWeightedScheduler will go through all the nodes as per topology information and it will pick the node which has less volume provisioned in the given pool. lets say there are 2 nodes node1 and node2 with below pool configuration :- ``` node1 | |-----> pool1 | | | |------> pvc1 | |------> pvc2 |-----> pool2 |------> pvc3 node2 | |-----> pool1 | | | |------> pvc4 |-----> pool2 |------> pvc5 |------> pvc6 ``` So if application is using pool1 as shown in the below storage class, then ZFS driver will schedule it on node2 as it has one volume as compared to node1 which has 2 volumes in pool1. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool1" ``` So if application is using pool2 as shown in the below storage class, then ZFS driver will schedule it on node1 as it has one volume only as compared node2 which has 2 volumes in pool2. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool2" ``` In case of same number of volumes on all the nodes for the given pool, it can pick any node and schedule the PV on that. Signed-off-by: Pawan <pawan@mayadata.io>
2019-11-06 21:20:49 +05:30
}
logrus.Infof("scheduled the volume %s/%s on node %s", pool, volName, selected)
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
volObj, err := volbuilder.NewBuilder().
WithName(volName).
WithCapacity(strconv.FormatInt(int64(size), 10)).
WithRecordSize(rs).
WithVolBlockSize(bs).
WithPoolName(pool).
WithDedup(dedup).
WithEncryption(encr).
WithKeyFormat(kf).
WithKeyLocation(kl).
WithThinProv(tp).
feat(ZFSPV): volume count based scheduler for ZFSPV (#8) This is an initial scheduler implementation for ZFS Local PV. * adding scheduler as a configurable option * adding volumeWeightedScheduler as scheduling logic The volumeWeightedScheduler will go through all the nodes as per topology information and it will pick the node which has less volume provisioned in the given pool. lets say there are 2 nodes node1 and node2 with below pool configuration :- ``` node1 | |-----> pool1 | | | |------> pvc1 | |------> pvc2 |-----> pool2 |------> pvc3 node2 | |-----> pool1 | | | |------> pvc4 |-----> pool2 |------> pvc5 |------> pvc6 ``` So if application is using pool1 as shown in the below storage class, then ZFS driver will schedule it on node2 as it has one volume as compared to node1 which has 2 volumes in pool1. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool1" ``` So if application is using pool2 as shown in the below storage class, then ZFS driver will schedule it on node1 as it has one volume only as compared node2 which has 2 volumes in pool2. ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: openebs-zfspv provisioner: zfs.csi.openebs.io parameters: blocksize: "4k" compression: "on" dedup: "on" thinprovision: "yes" poolname: "pool2" ``` In case of same number of volumes on all the nodes for the given pool, it can pick any node and schedule the PV on that. Signed-off-by: Pawan <pawan@mayadata.io>
2019-11-06 21:20:49 +05:30
WithOwnerNode(selected).
WithVolumeType(vtype).
WithVolumeStatus(zfs.ZFSStatusPending).
WithFsType(fstype).
WithCompression(compression).Build()
if err != nil {
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
return "", status.Error(codes.Internal, err.Error())
}
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
err = zfs.ProvisionVolume(volObj)
if err != nil {
feat(zfspv): handling unmounted volume There can be cases where openebs namespace has been accidently deleted (Optoro case: https://mdap.zendesk.com/agent/tickets/963), There the driver attempted to destroy the dataset which will first umount the dataset and then try to destroy it, the destroy will fail as volume is busy. Here, as mentioned in the steps to recover, we have to manually mount the dataset ``` 6. The driver might have attempted to destroy the volume before going down, which sets the mount as no(this strange behavior on gke ubuntu 18.04), we have to mount the dataset, go to the each node and check if there is any unmounted volume zfs get mounted if there is any unmounted dataset with this option as "no", we should do the below :- mountpath=zfs get -Hp -o value mountpoint <dataset name> zfs set mountpoint=none zfs set mountpoint=<mountpath> this will set the dataset to be mounted. ``` So in this case the volume will be unmounted and still mountpoint will set to the mountpath, so if application pod is deleted later on, it will try to mount the zfs dataset, here just setting the `mountpoint` is not sufficient, as if we have unmounted the zfs dataset (via zfs destroy in this case), so we have to explicitely mount the dataset **otherwise application will start running without any persistence storage**. Here automating the manual steps performed to resolve the problem, we are checking in the code that if zfs dataset is not mounted after setting the mountpoint property, attempt to mount it. This is not the case with the zvol as it does not attempt to unmount it, so zvols are fine. Also NodeUnPublish operation MUST be idempotent. If this RPC failed, or the CO does not know if it failed or not, it can choose to call NudeUnPublishRequest again. So handled this and returned successful if volume is not mounted also added descriptive error messages at few places. Signed-off-by: Pawan <pawan@mayadata.io>
2020-04-06 20:09:07 +05:30
return "", status.Errorf(codes.Internal,
"not able to provision the volume %s", err.Error())
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
}
return selected, nil
}
func CreateZFSClone(req *csi.CreateVolumeRequest, snapshot string) (string, error) {
volName := req.GetName()
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
size := req.GetCapacityRange().RequiredBytes
volsize := strconv.FormatInt(int64(size), 10)
snapshotID := strings.Split(snapshot, "@")
if len(snapshotID) != 2 {
return "", status.Errorf(
codes.Internal,
"snap name is not valid %s, {%s}",
snapshot,
"invalid snapshot name",
)
}
snap, err := zfs.GetZFSSnapshot(snapshotID[1])
if err != nil {
return "", status.Error(codes.Internal, err.Error())
}
if snap.Spec.PoolName != pool {
return "", status.Errorf(codes.Internal,
"clone to a different pool src pool %s dst pool %s",
snap.Spec.PoolName, pool)
}
if snap.Spec.Capacity != volsize {
return "", status.Error(codes.Internal, "clone volume size is not matching")
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
}
selected := snap.Spec.OwnerNodeID
volObj, err := volbuilder.NewBuilder().
WithName(volName).
WithVolumeStatus(zfs.ZFSStatusPending).
Build()
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
volObj.Spec = snap.Spec
volObj.Spec.SnapName = snapshot
err = zfs.ProvisionVolume(volObj)
if err != nil {
feat(zfspv): handling unmounted volume There can be cases where openebs namespace has been accidently deleted (Optoro case: https://mdap.zendesk.com/agent/tickets/963), There the driver attempted to destroy the dataset which will first umount the dataset and then try to destroy it, the destroy will fail as volume is busy. Here, as mentioned in the steps to recover, we have to manually mount the dataset ``` 6. The driver might have attempted to destroy the volume before going down, which sets the mount as no(this strange behavior on gke ubuntu 18.04), we have to mount the dataset, go to the each node and check if there is any unmounted volume zfs get mounted if there is any unmounted dataset with this option as "no", we should do the below :- mountpath=zfs get -Hp -o value mountpoint <dataset name> zfs set mountpoint=none zfs set mountpoint=<mountpath> this will set the dataset to be mounted. ``` So in this case the volume will be unmounted and still mountpoint will set to the mountpath, so if application pod is deleted later on, it will try to mount the zfs dataset, here just setting the `mountpoint` is not sufficient, as if we have unmounted the zfs dataset (via zfs destroy in this case), so we have to explicitely mount the dataset **otherwise application will start running without any persistence storage**. Here automating the manual steps performed to resolve the problem, we are checking in the code that if zfs dataset is not mounted after setting the mountpoint property, attempt to mount it. This is not the case with the zvol as it does not attempt to unmount it, so zvols are fine. Also NodeUnPublish operation MUST be idempotent. If this RPC failed, or the CO does not know if it failed or not, it can choose to call NudeUnPublishRequest again. So handled this and returned successful if volume is not mounted also added descriptive error messages at few places. Signed-off-by: Pawan <pawan@mayadata.io>
2020-04-06 20:09:07 +05:30
return "", status.Errorf(codes.Internal,
"not able to provision the clone volume %s", err.Error())
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
}
return selected, nil
}
// CreateVolume provisions a volume
func (cs *controller) CreateVolume(
ctx context.Context,
req *csi.CreateVolumeRequest,
) (*csi.CreateVolumeResponse, error) {
var err error
var selected string
volName := req.GetName()
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
size := req.GetCapacityRange().RequiredBytes
contentSource := req.GetVolumeContentSource()
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
if err = cs.validateVolumeCreateReq(req); err != nil {
return nil, err
}
selected, state, err := zfs.GetZFSVolumeState(req.Name)
if err == nil {
// ZFSVolume CR has been created, check if it is in Ready state
if state == zfs.ZFSStatusReady {
goto CreateVolumeResponse
}
return nil, status.Errorf(codes.Internal, "volume %s creation is Pending", volName)
}
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
if contentSource != nil && contentSource.GetSnapshot() != nil {
snapshotID := contentSource.GetSnapshot().GetSnapshotId()
selected, err = CreateZFSClone(req, snapshotID)
} else {
selected, err = CreateZFSVolume(req)
}
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
_, state, err = zfs.GetZFSVolumeState(req.Name)
if err != nil {
return nil, status.Errorf(codes.Internal, "createvolume: failed to fetch the volume %v", err.Error())
}
if state == zfs.ZFSStatusPending {
return nil, status.Errorf(codes.Internal, "volume %s is being created", volName)
}
CreateVolumeResponse:
sendEventOrIgnore(volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision)
topology := map[string]string{zfs.ZFSTopologyKey: selected}
cntx := map[string]string{zfs.PoolNameKey: pool}
return csipayload.NewCreateVolumeResponseBuilder().
WithName(volName).
WithCapacity(size).
WithTopology(topology).
WithContext(cntx).
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
WithContentSource(contentSource).
Build(), nil
}
// DeleteVolume deletes the specified volume
func (cs *controller) DeleteVolume(
ctx context.Context,
req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
logrus.Infof("received request to delete volume {%s}", req.VolumeId)
var (
err error
)
if err = cs.validateDeleteVolumeReq(req); err != nil {
return nil, err
}
volumeID := req.GetVolumeId()
// verify if the volume has already been deleted
vol, err := zfs.GetVolume(volumeID)
if vol != nil && vol.DeletionTimestamp != nil {
goto deleteResponse
}
// Delete the corresponding ZV CR
err = zfs.DeleteVolume(volumeID)
if err != nil {
return nil, errors.Wrapf(
err,
"failed to handle delete volume request for {%s}",
volumeID,
)
}
sendEventOrIgnore(volumeID, vol.Spec.Capacity, "zfs-localpv", analytics.VolumeDeprovision)
deleteResponse:
return csipayload.NewDeleteVolumeResponseBuilder().Build(), nil
}
// TODO Implementation will be taken up later
// ValidateVolumeCapabilities validates the capabilities
// required to create a new volume
// This implements csi.ControllerServer
func (cs *controller) ValidateVolumeCapabilities(
ctx context.Context,
req *csi.ValidateVolumeCapabilitiesRequest,
) (*csi.ValidateVolumeCapabilitiesResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// ControllerGetCapabilities fetches controller capabilities
//
// This implements csi.ControllerServer
func (cs *controller) ControllerGetCapabilities(
ctx context.Context,
req *csi.ControllerGetCapabilitiesRequest,
) (*csi.ControllerGetCapabilitiesResponse, error) {
resp := &csi.ControllerGetCapabilitiesResponse{
Capabilities: cs.capabilities,
}
return resp, nil
}
// ControllerExpandVolume resizes previously provisioned volume
//
// This implements csi.ControllerServer
func (cs *controller) ControllerExpandVolume(
ctx context.Context,
req *csi.ControllerExpandVolumeRequest,
) (*csi.ControllerExpandVolumeResponse, error) {
updatedSize := req.GetCapacityRange().GetRequiredBytes()
vol, err := zfs.GetZFSVolume(req.VolumeId)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to get ZFSVolume in for %s, {%s}",
req.VolumeId,
err.Error(),
)
}
volsize, err := strconv.ParseInt(vol.Spec.Capacity, 10, 64)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to parse volsize in for %s, {%s}",
req.VolumeId,
err.Error(),
)
}
/*
* Controller expand volume must be idempotent. If a volume corresponding
* to the specified volume ID is already larger than or equal to the target
* capacity of the expansion request, the plugin should reply 0 OK.
*/
if volsize >= updatedSize {
return csipayload.NewControllerExpandVolumeResponseBuilder().
WithCapacityBytes(volsize).
Build(), nil
}
if err := zfs.ResizeVolume(vol, updatedSize); err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to handle ControllerExpandVolumeRequest for %s, {%s}",
req.VolumeId,
err.Error(),
)
}
return csipayload.NewControllerExpandVolumeResponseBuilder().
WithCapacityBytes(updatedSize).
WithNodeExpansionRequired(true).
Build(), nil
}
// CreateSnapshot creates a snapshot for given volume
//
// This implements csi.ControllerServer
func (cs *controller) CreateSnapshot(
ctx context.Context,
req *csi.CreateSnapshotRequest,
) (*csi.CreateSnapshotResponse, error) {
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
logrus.Infof("CreateSnapshot volume %s@%s", req.SourceVolumeId, req.Name)
snapTimeStamp := time.Now().Unix()
state, err := zfs.GetZFSSnapshotStatus(req.Name)
if err == nil {
return csipayload.NewCreateSnapshotResponseBuilder().
WithSourceVolumeID(req.SourceVolumeId).
WithSnapshotID(req.SourceVolumeId+"@"+req.Name).
WithCreationTime(snapTimeStamp, 0).
WithReadyToUse(state == zfs.ZFSStatusReady).
Build(), nil
}
vol, err := zfs.GetZFSVolume(req.SourceVolumeId)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"CreateSnapshot not able to get volume %s: %s, {%s}",
req.SourceVolumeId, req.Name,
err.Error(),
)
}
labels := map[string]string{zfs.ZFSVolKey: vol.Name}
snapObj, err := snapbuilder.NewBuilder().
WithName(req.Name).
WithLabels(labels).Build()
if err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to create snapshotobject for %s: %s, {%s}",
req.SourceVolumeId, req.Name,
err.Error(),
)
}
snapObj.Spec = vol.Spec
snapObj.Status.State = zfs.ZFSStatusPending
if err := zfs.ProvisionSnapshot(snapObj); err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to handle CreateSnapshotRequest for %s: %s, {%s}",
req.SourceVolumeId, req.Name,
err.Error(),
)
}
state, _ = zfs.GetZFSSnapshotStatus(req.Name)
return csipayload.NewCreateSnapshotResponseBuilder().
WithSourceVolumeID(req.SourceVolumeId).
WithSnapshotID(req.SourceVolumeId+"@"+req.Name).
WithCreationTime(snapTimeStamp, 0).
WithReadyToUse(state == zfs.ZFSStatusReady).
Build(), nil
}
// DeleteSnapshot deletes given snapshot
//
// This implements csi.ControllerServer
func (cs *controller) DeleteSnapshot(
ctx context.Context,
req *csi.DeleteSnapshotRequest,
) (*csi.DeleteSnapshotResponse, error) {
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
logrus.Infof("DeleteSnapshot request for %s", req.SnapshotId)
// snapshodID is formed as <volname>@<snapname>
// parsing them here
snapshotID := strings.Split(req.SnapshotId, "@")
if len(snapshotID) != 2 {
return nil, status.Errorf(
codes.Internal,
"failed to handle DeleteSnapshot for %s, {%s}",
req.SnapshotId,
"failed to get the snapshot name, Manual intervention required",
)
}
if err := zfs.DeleteSnapshot(snapshotID[1]); err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to handle DeleteSnapshot for %s, {%s}",
req.SnapshotId,
err.Error(),
)
}
return &csi.DeleteSnapshotResponse{}, nil
}
// ListSnapshots lists all snapshots for the
// given volume
//
// This implements csi.ControllerServer
func (cs *controller) ListSnapshots(
ctx context.Context,
req *csi.ListSnapshotsRequest,
) (*csi.ListSnapshotsResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// ControllerUnpublishVolume removes a previously
// attached volume from the given node
//
// This implements csi.ControllerServer
func (cs *controller) ControllerUnpublishVolume(
ctx context.Context,
req *csi.ControllerUnpublishVolumeRequest,
) (*csi.ControllerUnpublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// ControllerPublishVolume attaches given volume
// at the specified node
//
// This implements csi.ControllerServer
func (cs *controller) ControllerPublishVolume(
ctx context.Context,
req *csi.ControllerPublishVolumeRequest,
) (*csi.ControllerPublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// GetCapacity return the capacity of the
// given volume
//
// This implements csi.ControllerServer
func (cs *controller) GetCapacity(
ctx context.Context,
req *csi.GetCapacityRequest,
) (*csi.GetCapacityResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// ListVolumes lists all the volumes
//
// This implements csi.ControllerServer
func (cs *controller) ListVolumes(
ctx context.Context,
req *csi.ListVolumesRequest,
) (*csi.ListVolumesResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
// validateCapabilities validates if provided capabilities
// are supported by this driver
func validateCapabilities(caps []*csi.VolumeCapability) bool {
for _, cap := range caps {
if !IsSupportedVolumeCapabilityAccessMode(cap.AccessMode.Mode) {
return false
}
}
return true
}
func (cs *controller) validateDeleteVolumeReq(req *csi.DeleteVolumeRequest) error {
volumeID := req.GetVolumeId()
if volumeID == "" {
return status.Error(
codes.InvalidArgument,
"failed to handle delete volume request: missing volume id",
)
}
err := cs.validateRequest(
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
)
if err != nil {
return errors.Wrapf(
err,
"failed to handle delete volume request for {%s} : validation failed",
volumeID,
)
}
return nil
}
// IsSupportedVolumeCapabilityAccessMode valides the requested access mode
func IsSupportedVolumeCapabilityAccessMode(
accessMode csi.VolumeCapability_AccessMode_Mode,
) bool {
for _, access := range SupportedVolumeCapabilityAccessModes {
if accessMode == access.Mode {
return true
}
}
return false
}
// newControllerCapabilities returns a list
// of this controller's capabilities
func newControllerCapabilities() []*csi.ControllerServiceCapability {
fromType := func(
cap csi.ControllerServiceCapability_RPC_Type,
) *csi.ControllerServiceCapability {
return &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: cap,
},
},
}
}
var capabilities []*csi.ControllerServiceCapability
for _, cap := range []csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
feat(zfspv): adding snapshot and clone support for ZFSPV (#39) This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps. Note: - Snapshot is created via reconciliation CR - Cloned volume will be on the same zpool where the snapshot is taken - Cloned volume will have same properties as source volume. ----------------------------------- Create a Snapshotclass ``` kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1beta1 metadata: name: zfspv-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" driver: zfs.csi.openebs.io deletionPolicy: Delete ``` Once snapshotclass is created, we can use this class to create a Snapshot ``` apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: zfspv-snap spec: volumeSnapshotClassName: zfspv-snapclass source: persistentVolumeClaimName: csi-zfspv ``` ``` $ kubectl get volumesnapshot NAME AGE zfspv-snap 7m52s ``` ``` $ kubectl get volumesnapshot -o yaml apiVersion: v1 items: - apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}} creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 name: zfspv-snap namespace: default resourceVersion: "30040" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca spec: source: persistentVolumeClaimName: csi-zfspv volumeSnapshotClassName: zfspv-snapclass status: boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca creationTime: "2020-01-30T10:31:24Z" readyToUse: true restoreSize: "0" kind: List metadata: resourceVersion: "" selfLink: "" ``` Openebs resource for the created snapshot ``` $ kubectl get snap -n openebs -o yaml apiVersion: v1 items: - apiVersion: openebs.io/v1alpha1 kind: ZFSSnapshot metadata: creationTimestamp: "2020-01-30T10:31:24Z" finalizers: - zfs.openebs.io/finalizer generation: 2 labels: kubernetes.io/nodename: pawan-2 openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca namespace: openebs resourceVersion: "30035" selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641 spec: capacity: "4294967296" fsType: zfs ownerNodeID: pawan-2 poolName: zfspv-pool status: Ready volumeType: DATASET kind: List metadata: resourceVersion: "" selfLink: "" ``` Create a clone volume We can provide a datasource as snapshot name to create a clone volume ```yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zfspv-clone spec: storageClassName: openebs-zfspv dataSource: name: zfspv-snap kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 4Gi ``` It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there. Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot. Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported. Signed-off-by: Pawan <pawan@mayadata.io>
2020-02-13 13:31:17 +05:30
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
} {
capabilities = append(capabilities, fromType(cap))
}
return capabilities
}
// validateRequest validates if the requested service is
// supported by the driver
func (cs *controller) validateRequest(
c csi.ControllerServiceCapability_RPC_Type,
) error {
for _, cap := range cs.capabilities {
if c == cap.GetRpc().GetType() {
return nil
}
}
return status.Error(
codes.InvalidArgument,
fmt.Sprintf("failed to validate request: {%s} is not supported", c),
)
}
func (cs *controller) validateVolumeCreateReq(req *csi.CreateVolumeRequest) error {
err := cs.validateRequest(
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
)
if err != nil {
return errors.Wrapf(
err,
"failed to handle create volume request for {%s}",
req.GetName(),
)
}
if req.GetName() == "" {
return status.Error(
codes.InvalidArgument,
"failed to handle create volume request: missing volume name",
)
}
volCapabilities := req.GetVolumeCapabilities()
if volCapabilities == nil {
return status.Error(
codes.InvalidArgument,
"failed to handle create volume request: missing volume capabilities",
)
}
return nil
}