From b71a9bfe4060ed384c43a130c0200a6ee66b8273 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Sat, 26 Jan 2019 00:39:46 +0530 Subject: [PATCH 1/2] Fix issue with error handling in metadata store Signed-off-by: Madhu Rajanna --- pkg/rbd/controllerserver.go | 9 +++++---- pkg/rbd/rbd.go | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index c731675fe..f886d819f 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -150,13 +150,13 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol glog.V(4).Infof("create volume %s", volName) } } - if err = cs.MetadataStore.Create(volumeID, rbdVol); err != nil { + if createErr := cs.MetadataStore.Create(volumeID, rbdVol); createErr != nil { glog.Warningf("failed to store volume metadata with error: %v", err) if err = deleteRBDImage(rbdVol, rbdVol.AdminID, req.GetSecrets()); err != nil { glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, rbdVol.VolName, err) return nil, err } - return nil, err + return nil, createErr } rbdVolumes[volumeID] = rbdVol @@ -341,7 +341,8 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS rbdSnap.CreatedAt = ptypes.TimestampNow().GetSeconds() - if err = cs.MetadataStore.Create(snapshotID, rbdSnap); err != nil { + if createErr := cs.MetadataStore.Create(snapshotID, rbdSnap); createErr != nil { + glog.Warningf("rbd: failed to store snapInfo with error: %v", err) // Unprotect snapshot err = unprotectSnapshot(rbdSnap, rbdSnap.AdminID, req.GetSecrets()) @@ -353,7 +354,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS if err = deleteSnapshot(rbdSnap, rbdSnap.AdminID, req.GetSecrets()); err != nil { return nil, status.Errorf(codes.Unknown, "This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err) } - return nil, err + return nil, createErr } rbdSnapshots[snapshotID] = rbdSnap diff --git a/pkg/rbd/rbd.go b/pkg/rbd/rbd.go index 0aea74764..abe2bdff4 100644 --- a/pkg/rbd/rbd.go +++ b/pkg/rbd/rbd.go @@ -93,6 +93,7 @@ func (r *Driver) Run(driverName, nodeID, endpoint string, containerized bool, ca csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME, csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT, csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS, + csi.ControllerServiceCapability_RPC_CLONE_VOLUME, }) r.cd.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER}) From 5b512cd48c5f6fdd65a3e1e7b773039c1acfbfce Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Sat, 26 Jan 2019 00:40:20 +0530 Subject: [PATCH 2/2] Add snapshot yaml files and volume clone capabilities to provisioner. Signed-off-by: Madhu Rajanna --- deploy/rbd/kubernetes/csi-provisioner-rbac.yaml | 12 ++++++++++++ .../kubernetes/csi-rbdplugin-provisioner.yaml | 15 +++++++++++++++ examples/rbd/pod-restore.yaml | 17 +++++++++++++++++ examples/rbd/pvc-restore.yaml | 16 ++++++++++++++++ examples/rbd/snapshot.yaml | 9 +++++++++ examples/rbd/snapshotclass.yaml | 11 +++++++++++ 6 files changed, 80 insertions(+) create mode 100644 examples/rbd/pod-restore.yaml create mode 100644 examples/rbd/pvc-restore.yaml create mode 100644 examples/rbd/snapshot.yaml create mode 100644 examples/rbd/snapshotclass.yaml diff --git a/deploy/rbd/kubernetes/csi-provisioner-rbac.yaml b/deploy/rbd/kubernetes/csi-provisioner-rbac.yaml index 6913e08c4..2aef1f1c6 100644 --- a/deploy/rbd/kubernetes/csi-provisioner-rbac.yaml +++ b/deploy/rbd/kubernetes/csi-provisioner-rbac.yaml @@ -27,9 +27,21 @@ rules: - apiGroups: [""] resources: ["endpoints"] verbs: ["get", "create", "update"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshots"] + verbs: ["get", "list", "watch", "update"] - apiGroups: [""] resources: ["configmaps"] verbs: ["get", "list", "create", "delete"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshotcontents"] + verbs: ["create", "get", "list", "watch", "update", "delete"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshotclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["create"] --- kind: ClusterRoleBinding diff --git a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml index 223419f54..305b6f46c 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml @@ -38,6 +38,21 @@ spec: volumeMounts: - name: socket-dir mountPath: /var/lib/kubelet/plugins/csi-rbdplugin + - name: csi-snapshotter + image: quay.io/k8scsi/csi-snapshotter:v1.0.1 + args: + - "--csi-address=$(ADDRESS)" + - "--connection-timeout=15s" + - "--v=5" + env: + - name: ADDRESS + value: /var/lib/kubelet/plugins/csi-rbdplugin/csi-provisioner.sock + imagePullPolicy: Always + securityContext: + privileged: true + volumeMounts: + - name: socket-dir + mountPath: /var/lib/kubelet/plugins/csi-rbdplugin - name: csi-rbdplugin securityContext: privileged: true diff --git a/examples/rbd/pod-restore.yaml b/examples/rbd/pod-restore.yaml new file mode 100644 index 000000000..b66474476 --- /dev/null +++ b/examples/rbd/pod-restore.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + name: csirbd-restore-demo-pod +spec: + containers: + - name: web-server + image: nginx + volumeMounts: + - name: mypvc + mountPath: /var/lib/www/html + volumes: + - name: mypvc + persistentVolumeClaim: + claimName: rbd-pvc-restore + readOnly: false + diff --git a/examples/rbd/pvc-restore.yaml b/examples/rbd/pvc-restore.yaml new file mode 100644 index 000000000..9db03c073 --- /dev/null +++ b/examples/rbd/pvc-restore.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: rbd-pvc-restore +spec: + storageClassName: csi-rbd + dataSource: + name: rbd-pvc-snapshot + kind: VolumeSnapshot + apiGroup: snapshot.storage.k8s.io + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi diff --git a/examples/rbd/snapshot.yaml b/examples/rbd/snapshot.yaml new file mode 100644 index 000000000..78a9f505d --- /dev/null +++ b/examples/rbd/snapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshot +metadata: + name: rbd-pvc-snapshot +spec: + snapshotClassName: csi-rbdplugin-snapclass + source: + name: rbd-pvc + kind: PersistentVolumeClaim diff --git a/examples/rbd/snapshotclass.yaml b/examples/rbd/snapshotclass.yaml new file mode 100644 index 000000000..778f2b084 --- /dev/null +++ b/examples/rbd/snapshotclass.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshotClass +metadata: + name: csi-rbdplugin-snapclass +snapshotter: csi-rbdplugin +parameters: + pool: rbd + monitors: mon1:port,mon2:port,... + csi.storage.k8s.io/snapshotter-secret-name: csi-rbd-secret + csi.storage.k8s.io/snapshotter-secret-namespace: default