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

Use sparse volumes #91

Closed
Closed
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
2 changes: 1 addition & 1 deletion cmd/hostpathplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
}

var (
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
endpoint = flag.String("endpoint", "unix://tmp/csi-hostpath.sock", "CSI endpoint")
driverName = flag.String("drivername", "hostpath.csi.k8s.io", "name of the driver")
nodeID = flag.String("nodeid", "", "node id")
ephemeral = flag.Bool("ephemeral", false, "publish volumes in ephemeral mode even if kubelet did not ask for it (only needed for Kubernetes 1.15)")
Expand Down
13 changes: 10 additions & 3 deletions pkg/hostpath/hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func getVolumePath(volID string) string {
return filepath.Join(dataRoot, volID)
}

// createVolume create the directory for the hostpath volume.
// createVolume create the sparse ext2 filesystem for the hostpath volume.
// It returns the volume path or err if one occurs.
func createHostpathVolume(volID, name string, cap int64, volAccessType accessType, ephemeral bool) (*hostPathVolume, error) {
path := getVolumePath(volID)
Expand All @@ -177,10 +177,17 @@ func createHostpathVolume(volID, name string, cap int64, volAccessType accessTyp
case blockAccess:
executor := utilexec.New()
size := fmt.Sprintf("%dM", cap/mib)

// Create a block file.
out, err := executor.Command("fallocate", "-l", size, path).CombinedOutput()
out, err := executor.Command("dd", "if=/dev/zero", "bs=1", "count=0", String.Join("seek=", size), String.Join("of=", path)).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to create block device allocation: %v, %v", err, string(out))
}

//Format a block file
out, err := executor.Command("mkfs.ext2", "-q", path).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to create block device: %v, %v", err, string(out))
return nil, fmt.Errorf("failed to create ext2 filesystem on block device allocation: %v, %v", err, string(out))
}

// Associate block file with the loop device.
Expand Down