Skip to content

Commit f84a2f5

Browse files
authored
Merge pull request #42 from aayushrangwala/aayushrangwala/Block-vol-support-#41
Fixed the Raw Block PV snapshot support
2 parents ac1ccd7 + 6c3c040 commit f84a2f5

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
name: csi-data-dir
6464

6565
- name: hostpath
66-
image: quay.io/k8scsi/hostpathplugin:v1.1.0-rc1
66+
image: quay.io/k8scsi/hostpathplugin:canary
6767
args:
6868
- "--v=5"
6969
- "--endpoint=$(CSI_ENDPOINT)"
@@ -99,6 +99,8 @@ spec:
9999
- mountPath: /var/lib/kubelet/plugins
100100
mountPropagation: Bidirectional
101101
name: plugins-dir
102+
- mountPath: /csi-data-dir
103+
name: csi-data-dir
102104

103105
- name: liveness-probe
104106
volumeMounts:

deploy/master/hostpath/csi-hostpath-plugin.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ spec:
9999
- mountPath: /var/lib/kubelet/plugins
100100
mountPropagation: Bidirectional
101101
name: plugins-dir
102+
- mountPath: /csi-data-dir
103+
name: csi-data-dir
102104

103105
- name: liveness-probe
104106
volumeMounts:

examples/csi-pod-raw.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: pod-raw
5+
labels:
6+
name: busybox-test
7+
spec:
8+
restartPolicy: Always
9+
containers:
10+
- image: gcr.io/google_containers/busybox
11+
command: ["/bin/sh", "-c"]
12+
args: [ "tail -f /dev/null" ]
13+
name: busybox
14+
volumeDevices:
15+
- name: vol
16+
devicePath: /dev/loop3 # This device path needs to be replaced with the site specific
17+
volumes:
18+
- name: vol
19+
persistentVolumeClaim:
20+
claimName: pvc-raw

examples/csi-pvc-raw.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: PersistentVolumeClaim
2+
apiVersion: v1
3+
metadata:
4+
name: pvc-raw
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
storageClassName: csi-hostpath-sc
9+
volumeMode: Block
10+
resources:
11+
requests:
12+
storage: 1Gi

examples/csi-raw-pv-snapshot.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: snapshot.storage.k8s.io/v1alpha1
2+
kind: VolumeSnapshot
3+
metadata:
4+
name: raw-pv-snapshot
5+
spec:
6+
snapshotClassName: csi-hostpath-snapclass
7+
source:
8+
name: pvc-raw
9+
kind: PersistentVolumeClaim

pkg/hostpath/controllerserver.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"sort"
2424
"strconv"
25+
"strings"
2526

2627
"github.com/golang/protobuf/ptypes"
2728

@@ -346,8 +347,16 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
346347
snapshotID := uuid.NewUUID().String()
347348
creationTime := ptypes.TimestampNow()
348349
volPath := hostPathVolume.VolPath
349-
file := snapshotRoot + snapshotID + ".tgz"
350-
args := []string{"czf", file, "-C", volPath, "."}
350+
filePath := []string{snapshotRoot, "/", snapshotID, ".tgz"}
351+
file := strings.Join(filePath, "")
352+
args := []string{}
353+
if hostPathVolume.VolAccessType == blockAccess {
354+
glog.V(4).Infof("Creating snapshot of Raw Block Mode Volume")
355+
args = []string{"czf", file, volPath}
356+
} else {
357+
glog.V(4).Infof("Creating snapshot of Filsystem Mode Volume")
358+
args = []string{"czf", file, "-C", volPath, "."}
359+
}
351360
executor := utilexec.New()
352361
out, err := executor.Command("tar", args...).CombinedOutput()
353362
if err != nil {
@@ -389,7 +398,8 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
389398
}
390399
snapshotID := req.GetSnapshotId()
391400
glog.V(4).Infof("deleting volume %s", snapshotID)
392-
path := snapshotRoot + snapshotID + ".tgz"
401+
pathSlice := []string{snapshotRoot, "/", snapshotID, ".tgz"}
402+
path := strings.Join(pathSlice, "")
393403
os.RemoveAll(path)
394404
delete(hostPathVolumeSnapshots, snapshotID)
395405
return &csi.DeleteSnapshotResponse{}, nil

0 commit comments

Comments
 (0)