From d20999ff6b38b55e3b79dba13c83fc53fb0cebbd Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Mon, 15 Apr 2019 20:24:30 +0530 Subject: [PATCH 1/4] Fixed the Raw Block PV snapshot support --- .../hostpath/csi-hostpath-plugin.yaml | 2 ++ pkg/hostpath/controllerserver.go | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml index 52bab24a8..77374792b 100644 --- a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml +++ b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml @@ -99,6 +99,8 @@ spec: - mountPath: /var/lib/kubelet/plugins mountPropagation: Bidirectional name: plugins-dir + - mountPath: /csi-data-dir + name: csi-data-dir - name: liveness-probe volumeMounts: diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index 789638f43..fa1a1d2c2 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -38,8 +38,8 @@ import ( const ( deviceID = "deviceID" - provisionRoot = "/csi-data-dir" - snapshotRoot = "/csi-data-dir" + provisionRoot = "/csi-data-dir/" + snapshotRoot = "/csi-data-dir/" maxStorageCapacity = tib ) @@ -347,7 +347,14 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS creationTime := ptypes.TimestampNow() volPath := hostPathVolume.VolPath file := snapshotRoot + snapshotID + ".tgz" - args := []string{"czf", file, "-C", volPath, "."} + args := []string{} + if hostPathVolume.VolAccessType == blockAccess { + glog.V(4).Infof("Creating snapshot of Raw Block Mode Volume") + args = []string{"czf", file, volPath} + } else { + glog.V(4).Infof("Creating snapshot of Filsystem Mode Volume") + args = []string{"czf", file, "-C", volPath, "."} + } executor := utilexec.New() out, err := executor.Command("tar", args...).CombinedOutput() if err != nil { From 96b6555ace9c6467b76c6d7664b769401ae78810 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Tue, 16 Apr 2019 09:42:30 +0530 Subject: [PATCH 2/4] Examples: Create a Block Mode PV and it's Snapshot --- examples/csi-pod-raw.yaml | 20 ++++++++++++++++++++ examples/csi-pvc-raw.yaml | 12 ++++++++++++ examples/csi-raw-pv-snapshot.yaml | 9 +++++++++ 3 files changed, 41 insertions(+) create mode 100644 examples/csi-pod-raw.yaml create mode 100644 examples/csi-pvc-raw.yaml create mode 100644 examples/csi-raw-pv-snapshot.yaml diff --git a/examples/csi-pod-raw.yaml b/examples/csi-pod-raw.yaml new file mode 100644 index 000000000..4b7149aec --- /dev/null +++ b/examples/csi-pod-raw.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Pod +metadata: + name: pod-raw + labels: + name: busybox-test +spec: + restartPolicy: Always + containers: + - image: gcr.io/google_containers/busybox + command: ["/bin/sh", "-c"] + args: [ "tail -f /dev/null" ] + name: busybox + volumeDevices: + - name: vol + devicePath: /dev/loop3 # This device path needs to be replaced with the site specific + volumes: + - name: vol + persistentVolumeClaim: + claimName: pvc-raw diff --git a/examples/csi-pvc-raw.yaml b/examples/csi-pvc-raw.yaml new file mode 100644 index 000000000..b770c58d2 --- /dev/null +++ b/examples/csi-pvc-raw.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: pvc-raw +spec: + accessModes: + - ReadWriteOnce + storageClassName: csi-hostpath-sc + volumeMode: Block + resources: + requests: + storage: 1Gi diff --git a/examples/csi-raw-pv-snapshot.yaml b/examples/csi-raw-pv-snapshot.yaml new file mode 100644 index 000000000..b3457c0ed --- /dev/null +++ b/examples/csi-raw-pv-snapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshot +metadata: + name: raw-pv-snapshot +spec: + snapshotClassName: csi-hostpath-snapclass + source: + name: pvc-raw + kind: PersistentVolumeClaim From 90edc79a9973b5dbc64205bdc460b28e620e6c14 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Thu, 18 Apr 2019 10:57:58 +0530 Subject: [PATCH 3/4] Added MountPath in deploy/master/hostpath also and changed the hostpath-plugin image version to canary --- deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml | 4 ++-- deploy/master/hostpath/csi-hostpath-plugin.yaml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml index 77374792b..cca1e83d5 100644 --- a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml +++ b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml @@ -37,7 +37,7 @@ spec: hostNetwork: true containers: - name: node-driver-registrar - image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2 + image: quay.io/k8scsi/csi-node-driver-registrar:canary lifecycle: preStop: exec: @@ -63,7 +63,7 @@ spec: name: csi-data-dir - name: hostpath - image: quay.io/k8scsi/hostpathplugin:v1.1.0-rc1 + image: quay.io/k8scsi/hostpathplugin:canary args: - "--v=5" - "--endpoint=$(CSI_ENDPOINT)" diff --git a/deploy/master/hostpath/csi-hostpath-plugin.yaml b/deploy/master/hostpath/csi-hostpath-plugin.yaml index d7cf2cf58..49a748d2c 100644 --- a/deploy/master/hostpath/csi-hostpath-plugin.yaml +++ b/deploy/master/hostpath/csi-hostpath-plugin.yaml @@ -99,6 +99,8 @@ spec: - mountPath: /var/lib/kubelet/plugins mountPropagation: Bidirectional name: plugins-dir + - mountPath: /csi-data-dir + name: csi-data-dir - name: liveness-probe volumeMounts: From 6c3c0409f7b2514cb74f127805b299b8521dd174 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Fri, 19 Apr 2019 11:04:31 +0530 Subject: [PATCH 4/4] corrected the node-registrar image version to v1.0.2 to be aligned with all the side cars and used strings.Join() to concatenate the path string for volume --- .../kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml | 2 +- pkg/hostpath/controllerserver.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml index cca1e83d5..774f564ea 100644 --- a/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml +++ b/deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml @@ -37,7 +37,7 @@ spec: hostNetwork: true containers: - name: node-driver-registrar - image: quay.io/k8scsi/csi-node-driver-registrar:canary + image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2 lifecycle: preStop: exec: diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index fa1a1d2c2..5c7eca19a 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -22,6 +22,7 @@ import ( "os" "sort" "strconv" + "strings" "github.com/golang/protobuf/ptypes" @@ -38,8 +39,8 @@ import ( const ( deviceID = "deviceID" - provisionRoot = "/csi-data-dir/" - snapshotRoot = "/csi-data-dir/" + provisionRoot = "/csi-data-dir" + snapshotRoot = "/csi-data-dir" maxStorageCapacity = tib ) @@ -346,7 +347,8 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS snapshotID := uuid.NewUUID().String() creationTime := ptypes.TimestampNow() volPath := hostPathVolume.VolPath - file := snapshotRoot + snapshotID + ".tgz" + filePath := []string{snapshotRoot, "/", snapshotID, ".tgz"} + file := strings.Join(filePath, "") args := []string{} if hostPathVolume.VolAccessType == blockAccess { glog.V(4).Infof("Creating snapshot of Raw Block Mode Volume") @@ -396,7 +398,8 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS } snapshotID := req.GetSnapshotId() glog.V(4).Infof("deleting volume %s", snapshotID) - path := snapshotRoot + snapshotID + ".tgz" + pathSlice := []string{snapshotRoot, "/", snapshotID, ".tgz"} + path := strings.Join(pathSlice, "") os.RemoveAll(path) delete(hostPathVolumeSnapshots, snapshotID) return &csi.DeleteSnapshotResponse{}, nil