diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 18c6c0a7899f7..1b1cddd961d09 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -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 diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index 7fb89f688ba36..fe455e91c4105 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -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"))