Skip to content

Commit 13fef84

Browse files
authored
Merge pull request #842 from andyzhangx/useTarCommandInSnapshot
feat: add useTarCommandInSnapshot flag in chart config
2 parents edc83fb + def3c6f commit 13fef84

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed
45 Bytes
Binary file not shown.

charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ spec:
181181
- "--mount-permissions={{ .Values.driver.mountPermissions }}"
182182
- "--working-mount-dir={{ .Values.controller.workingMountDir }}"
183183
- "--default-ondelete-policy={{ .Values.controller.defaultOnDeletePolicy }}"
184+
- "--use-tar-command-in-snapshot={{ .Values.controller.useTarCommandInSnapshot }}"
184185
env:
185186
- name: NODE_ID
186187
valueFrom:

charts/latest/csi-driver-nfs/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ controller:
5757
runOnMaster: false
5858
runOnControlPlane: false
5959
enableSnapshotter: true
60+
useTarCommandInSnapshot: false
6061
livenessProbe:
6162
healthPort: 29652
6263
logLevel: 5

cmd/nfsplugin/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume")
3535
volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
3636
removeArchivedVolumePath = flag.Bool("remove-archived-volume-path", false, "remove archived volume path in DeleteVolume")
37+
useTarCommandInSnapshot = flag.Bool("use-tar-command-in-snapshot", false, "use tar command to pack and unpack snapshot data")
3738
)
3839

3940
func main() {
@@ -58,6 +59,7 @@ func handle() {
5859
DefaultOnDeletePolicy: *defaultOnDeletePolicy,
5960
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
6061
RemoveArchivedVolumePath: *removeArchivedVolumePath,
62+
UseTarCommandInSnapshot: *useTarCommandInSnapshot,
6163
}
6264
d := nfs.NewDriver(&driverOptions)
6365
d.Run(false)

pkg/nfs/controllerserver.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,14 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
406406
dstPath := filepath.Join(snapInternalVolPath, snapshot.archiveName())
407407

408408
klog.V(2).Infof("tar %v -> %v", srcPath, dstPath)
409-
err = TarPack(srcPath, dstPath, true)
410-
if err != nil {
411-
return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v", err)
409+
if cs.Driver.useTarCommandInSnapshot {
410+
if out, err := exec.Command("tar", "-C", srcPath, "-czvf", dstPath, ".").CombinedOutput(); err != nil {
411+
return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v: %v", err, string(out))
412+
}
413+
} else {
414+
if err := TarPack(srcPath, dstPath, true); err != nil {
415+
return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v", err)
416+
}
412417
}
413418
klog.V(2).Infof("tar %s -> %s complete", srcPath, dstPath)
414419

@@ -573,9 +578,14 @@ func (cs *ControllerServer) copyFromSnapshot(ctx context.Context, req *csi.Creat
573578
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
574579
klog.V(2).Infof("copy volume from snapshot %v -> %v", snapPath, dstPath)
575580

576-
err = TarUnpack(snapPath, dstPath, true)
577-
if err != nil {
578-
return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v", err)
581+
if cs.Driver.useTarCommandInSnapshot {
582+
if out, err := exec.Command("tar", "-xzvf", snapPath, "-C", dstPath).CombinedOutput(); err != nil {
583+
return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v: %v", err, string(out))
584+
}
585+
} else {
586+
if err := TarUnpack(snapPath, dstPath, true); err != nil {
587+
return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v", err)
588+
}
579589
}
580590
klog.V(2).Infof("volume copied from snapshot %v -> %v", snapPath, dstPath)
581591
return nil

pkg/nfs/nfs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type DriverOptions struct {
3838
DefaultOnDeletePolicy string
3939
VolStatsCacheExpireInMinutes int
4040
RemoveArchivedVolumePath bool
41+
UseTarCommandInSnapshot bool
4142
}
4243

4344
type Driver struct {
@@ -49,6 +50,7 @@ type Driver struct {
4950
workingMountDir string
5051
defaultOnDeletePolicy string
5152
removeArchivedVolumePath bool
53+
useTarCommandInSnapshot bool
5254

5355
//ids *identityServer
5456
ns *NodeServer
@@ -96,6 +98,7 @@ func NewDriver(options *DriverOptions) *Driver {
9698
workingMountDir: options.WorkingMountDir,
9799
volStatsCacheExpireInMinutes: options.VolStatsCacheExpireInMinutes,
98100
removeArchivedVolumePath: options.RemoveArchivedVolumePath,
101+
useTarCommandInSnapshot: options.UseTarCommandInSnapshot,
99102
}
100103

101104
n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{

0 commit comments

Comments
 (0)