Merge pull request #79784 from cwdsuzhou/July/RemoveDeviceVolumeDir

Bugfix: remove PV dir when umount raw block device
This commit is contained in:
Kubernetes Prow Robot 2019-09-27 02:03:36 -07:00 committed by GitHub
commit a392897dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"k8s.io/klog"
@ -361,5 +362,25 @@ func (m *csiBlockMapper) TearDownDevice(globalMapPath, devicePath string) error
}
}
dataDir := getVolumeDeviceDataDir(m.specName, m.plugin.host)
// remove ~/${pv}/data/vol_data.json first, then remove the other dir.
volDataFile := path.Join(dataDir, volDataFileName)
err = os.Remove(volDataFile)
if err != nil && !os.IsNotExist(err) {
return err
}
// remove ~/${pv}/data
err = os.Remove(dataDir)
if err != nil && !os.IsNotExist(err) {
return err
}
// remove ~/${pv}
pvPath := filepath.Dir(dataDir)
err = os.Remove(pvPath)
if err != nil && !os.IsNotExist(err) {
return err
}
return nil
}