Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Raw Block PV snapshot support #42

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
aayushrangwala marked this conversation as resolved.
Show resolved Hide resolved
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
aayushrangwala marked this conversation as resolved.
Show resolved Hide resolved

- 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