feat: add useTarCommandInSnapshot flag in chart config

This commit is contained in:
andyzhangx 2025-01-14 14:19:50 +00:00
parent 62721d8487
commit def3c6fb65
6 changed files with 23 additions and 6 deletions

View File

@ -181,6 +181,7 @@ spec:
- "--mount-permissions={{ .Values.driver.mountPermissions }}" - "--mount-permissions={{ .Values.driver.mountPermissions }}"
- "--working-mount-dir={{ .Values.controller.workingMountDir }}" - "--working-mount-dir={{ .Values.controller.workingMountDir }}"
- "--default-ondelete-policy={{ .Values.controller.defaultOnDeletePolicy }}" - "--default-ondelete-policy={{ .Values.controller.defaultOnDeletePolicy }}"
- "--use-tar-command-in-snapshot={{ .Values.controller.useTarCommandInSnapshot }}"
env: env:
- name: NODE_ID - name: NODE_ID
valueFrom: valueFrom:

View File

@ -57,6 +57,7 @@ controller:
runOnMaster: false runOnMaster: false
runOnControlPlane: false runOnControlPlane: false
enableSnapshotter: true enableSnapshotter: true
useTarCommandInSnapshot: false
livenessProbe: livenessProbe:
healthPort: 29652 healthPort: 29652
logLevel: 5 logLevel: 5

View File

@ -34,6 +34,7 @@ var (
defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume") defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume")
volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache") volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
removeArchivedVolumePath = flag.Bool("remove-archived-volume-path", false, "remove archived volume path in DeleteVolume") removeArchivedVolumePath = flag.Bool("remove-archived-volume-path", false, "remove archived volume path in DeleteVolume")
useTarCommandInSnapshot = flag.Bool("use-tar-command-in-snapshot", false, "use tar command to pack and unpack snapshot data")
) )
func main() { func main() {
@ -58,6 +59,7 @@ func handle() {
DefaultOnDeletePolicy: *defaultOnDeletePolicy, DefaultOnDeletePolicy: *defaultOnDeletePolicy,
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes, VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
RemoveArchivedVolumePath: *removeArchivedVolumePath, RemoveArchivedVolumePath: *removeArchivedVolumePath,
UseTarCommandInSnapshot: *useTarCommandInSnapshot,
} }
d := nfs.NewDriver(&driverOptions) d := nfs.NewDriver(&driverOptions)
d.Run(false) d.Run(false)

View File

@ -406,9 +406,14 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
dstPath := filepath.Join(snapInternalVolPath, snapshot.archiveName()) dstPath := filepath.Join(snapInternalVolPath, snapshot.archiveName())
klog.V(2).Infof("tar %v -> %v", srcPath, dstPath) klog.V(2).Infof("tar %v -> %v", srcPath, dstPath)
err = TarPack(srcPath, dstPath, true) if cs.Driver.useTarCommandInSnapshot {
if err != nil { if out, err := exec.Command("tar", "-C", srcPath, "-czvf", dstPath, ".").CombinedOutput(); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v", err) return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v: %v", err, string(out))
}
} else {
if err := TarPack(srcPath, dstPath, true); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create archive for snapshot: %v", err)
}
} }
klog.V(2).Infof("tar %s -> %s complete", srcPath, dstPath) klog.V(2).Infof("tar %s -> %s complete", srcPath, dstPath)
@ -573,9 +578,14 @@ func (cs *ControllerServer) copyFromSnapshot(ctx context.Context, req *csi.Creat
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol) dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
klog.V(2).Infof("copy volume from snapshot %v -> %v", snapPath, dstPath) klog.V(2).Infof("copy volume from snapshot %v -> %v", snapPath, dstPath)
err = TarUnpack(snapPath, dstPath, true) if cs.Driver.useTarCommandInSnapshot {
if err != nil { if out, err := exec.Command("tar", "-xzvf", snapPath, "-C", dstPath).CombinedOutput(); err != nil {
return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v", err) return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v: %v", err, string(out))
}
} else {
if err := TarUnpack(snapPath, dstPath, true); err != nil {
return status.Errorf(codes.Internal, "failed to copy volume for snapshot: %v", err)
}
} }
klog.V(2).Infof("volume copied from snapshot %v -> %v", snapPath, dstPath) klog.V(2).Infof("volume copied from snapshot %v -> %v", snapPath, dstPath)
return nil return nil

View File

@ -38,6 +38,7 @@ type DriverOptions struct {
DefaultOnDeletePolicy string DefaultOnDeletePolicy string
VolStatsCacheExpireInMinutes int VolStatsCacheExpireInMinutes int
RemoveArchivedVolumePath bool RemoveArchivedVolumePath bool
UseTarCommandInSnapshot bool
} }
type Driver struct { type Driver struct {
@ -49,6 +50,7 @@ type Driver struct {
workingMountDir string workingMountDir string
defaultOnDeletePolicy string defaultOnDeletePolicy string
removeArchivedVolumePath bool removeArchivedVolumePath bool
useTarCommandInSnapshot bool
//ids *identityServer //ids *identityServer
ns *NodeServer ns *NodeServer
@ -96,6 +98,7 @@ func NewDriver(options *DriverOptions) *Driver {
workingMountDir: options.WorkingMountDir, workingMountDir: options.WorkingMountDir,
volStatsCacheExpireInMinutes: options.VolStatsCacheExpireInMinutes, volStatsCacheExpireInMinutes: options.VolStatsCacheExpireInMinutes,
removeArchivedVolumePath: options.RemoveArchivedVolumePath, removeArchivedVolumePath: options.RemoveArchivedVolumePath,
useTarCommandInSnapshot: options.UseTarCommandInSnapshot,
} }
n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{ n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{