From 902c652ccb0a25908973091dfb46f816a1af0b8d Mon Sep 17 00:00:00 2001 From: Humble Devassy Chirammal Date: Mon, 6 Oct 2025 15:44:48 +0530 Subject: [PATCH] Record proper orphaned pod cleanup error based on the system call The code actually calls os.Remove(), not rmdir(). The error message should accurately reflect the operation being performed. os.Remove() can remove both files and directories, while rmdir() only removes directories Signed-off-by: Humble Devassy Chirammal --- pkg/kubelet/kubelet_volumes.go | 6 +++--- pkg/volume/csi/csi_mounter.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/kubelet_volumes.go b/pkg/kubelet/kubelet_volumes.go index 40320dcdf55..9e0bd818490 100644 --- a/pkg/kubelet/kubelet_volumes.go +++ b/pkg/kubelet/kubelet_volumes.go @@ -145,7 +145,7 @@ func (kl *Kubelet) removeOrphanedPodVolumeDirs(uid types.UID) []error { for _, subpathVolumePath := range subpathVolumePaths { // Remove both files and empty directories here, as the subpath may have been a bind-mount of a file or a directory. if err := os.Remove(subpathVolumePath); err != nil { - orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("orphaned pod %q found, but failed to rmdir() subpath at path %v: %v", uid, subpathVolumePath, err)) + orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("orphaned pod %q found, but failed to remove subpath at path %v: %w", uid, subpathVolumePath, err)) } else { klog.InfoS("Cleaned up orphaned volume subpath from pod", "podUID", uid, "path", subpathVolumePath) } @@ -201,7 +201,7 @@ func (kl *Kubelet) cleanupOrphanedPodDirs(pods []*v1.Pod, runningPods []*kubecon continue } - // Attempt to remove the pod volumes directory and its subdirs + // Attempt to remove the pod volumes directory and its subdirectories podVolumeErrors := kl.removeOrphanedPodVolumeDirs(uid) if len(podVolumeErrors) > 0 { errorPods++ @@ -214,7 +214,7 @@ func (kl *Kubelet) cleanupOrphanedPodDirs(pods []*v1.Pod, runningPods []*kubecon continue } - // Call RemoveAllOneFilesystem for remaining subdirs under the pod directory + // Call RemoveAllOneFilesystem for remaining subdirectories under the pod directory podDir := kl.getPodDir(uid) podSubdirs, err := os.ReadDir(podDir) if err != nil { diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index f8760280dcb..63ac8341074 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -453,7 +453,7 @@ func (c *csiMountMgr) TearDownAt(dir string) error { // to the spec. // // Kubelet should only be responsible for removal of json data files it - // creates and parent directories. + // creates and their parent directories. // // However, some CSI plugins maybe buggy and don't adhere to the standard, // so we still need to remove the target_path here if it's unmounted and