From 2bd3ec1afbf861a642cbefb9b947b1f560c8b2fc Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Thu, 7 Aug 2025 11:40:19 +0300 Subject: [PATCH] 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 (cherry picked from commit 87165cc6d1fe73f18a494eefad966fca0a1e84db) --- pkg/daemon/ceph/cleanup/hostpath.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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) {