Skip to content

Commit

Permalink
do not remove volume dir when saveVolumeData fails
Browse files Browse the repository at this point in the history
  • Loading branch information
fankangbest authored and huffmanca committed Feb 9, 2021
1 parent 217a1c4 commit f0a40f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 3 additions & 5 deletions pkg/volume/csi/csi_attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,9 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
volDataKey.driverName: csiSource.Driver,
}
if err = saveVolumeData(dataDir, volDataFileName, data); err != nil {
klog.Error(log("failed to save volume info data: %v", err))
if cleanErr := os.RemoveAll(dataDir); cleanErr != nil {
klog.Error(log("failed to remove dir after error [%s]: %v", dataDir, cleanErr))
}
return err
errMsg := log("failed to save volume info data: %v", err)
klog.Error(errMsg)
return errors.New(errMsg)
}
defer func() {
// Only if there was an error and volume operation was considered
Expand Down
11 changes: 8 additions & 3 deletions pkg/volume/csi/csi_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,15 @@ func (p *csiPlugin) NewMounter(
volData[volDataKey.attachmentID] = attachID

if err := saveVolumeData(dataDir, volDataFileName, volData); err != nil {
if removeErr := os.RemoveAll(dataDir); removeErr != nil {
klog.Error(log("failed to remove dir after error [%s]: %v", dataDir, removeErr))
errorMsg := log("csi.NewMounter failed to save volume info data: %v", err)
klog.Error(errorMsg)

// attempt to cleanup volume mount dir.
if removeMountDirErr := removeMountDir(p, dir); removeMountDirErr != nil {
klog.Error(log("csi.NewMounter failed to remove mount dir [%s]: %v", dir, removeMountDirErr))
}
return nil, errors.New(log("failed to save volume info data: %v", err))

return nil, errors.New(errorMsg)
}

klog.V(4).Info(log("mounter created successfully"))
Expand Down

0 comments on commit f0a40f4

Please sign in to comment.