core: cleanup csi-related folders from /var/lib/rook during uninstall

delete csi-related directories from /var/lib/rook that
match the suffix `.csi.ceph.com`.
these folders were used in earlier versions when rook managed
cephcsi directly. in later versions, logs and data are redirected
to /var/lib/cephcsi, but legacy paths may still exist and require
cleanup during uninstall.
this change improves cleanup completeness for odf 4.18 and earlier.

example of directories removed:
- /var/lib/rook/openshift-storage.cephfs.csi.ceph.com
- /var/lib/rook/openshift-storage.rbd.csi.ceph.com

Signed-off-by: Oded Viner <oviner@redhat.com>
(cherry picked from commit 87165cc6d1)
This commit is contained in:
Oded Viner authored and Mergify committed 2025-08-07 16:24:10 +00:00
1 parent 43e80d741a
commit 2bd3ec1afb
1 file changed
+24
+24
View File
@@ -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) {