Skip to content

Commit

Permalink
Merge pull request #42 from aayushrangwala/aayushrangwala/Block-vol-s…
Browse files Browse the repository at this point in the history
…upport-#41

Fixed the Raw Block PV snapshot support
  • Loading branch information
k8s-ci-robot authored Apr 19, 2019
2 parents ac1ccd7 + 6c3c040 commit f84a2f5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
4 changes: 3 additions & 1 deletion deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions deploy/master/hostpath/csi-hostpath-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions examples/csi-pod-raw.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions examples/csi-pvc-raw.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions examples/csi-raw-pv-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"sort"
"strconv"
"strings"

"github.com/golang/protobuf/ptypes"

Expand Down Expand Up @@ -346,8 +347,16 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
snapshotID := uuid.NewUUID().String()
creationTime := ptypes.TimestampNow()
volPath := hostPathVolume.VolPath
file := snapshotRoot + snapshotID + ".tgz"
args := []string{"czf", file, "-C", volPath, "."}
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")
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 {
Expand Down Expand Up @@ -389,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
Expand Down

0 comments on commit f84a2f5

Please sign in to comment.