diff --git a/pkg/daemon/ceph/cleanup/hostpath.go b/pkg/daemon/ceph/cleanup/hostpath.go index 76db2f02a..758990d1e 100644 --- a/pkg/daemon/ceph/cleanup/hostpath.go +++ b/pkg/daemon/ceph/cleanup/hostpath.go @@ -20,6 +20,7 @@ import ( "os" "path" "path/filepath" + "strings" "github.com/pkg/errors" opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" @@ -36,6 +37,29 @@ func StartHostPathCleanup(namespaceDir, dataDirHostPath, monSecret string) { cleanMonDirs(dataDirHostPath, monSecret) cleanExporterDir(dataDirHostPath) + cleanCSIDirs(dataDirHostPath) +} + +func cleanCSIDirs(dataDirHostPath string) { + entries, err := os.ReadDir(dataDirHostPath) + if err != nil { + logger.Errorf("failed to read directory %q. %v", dataDirHostPath, err) + return + } + + for _, entry := range entries { + if entry.IsDir() { + name := entry.Name() + if strings.HasSuffix(name, ".csi.ceph.com") { + fullPath := filepath.Join(dataDirHostPath, name) + if err := os.RemoveAll(fullPath); err != nil { + logger.Errorf("failed to remove CSI directory %q. %v", fullPath, err) + } else { + logger.Infof("successfully removed CSI directory %q", fullPath) + } + } + } + } } func cleanExporterDir(dataDirHostPath string) {