orphanVolumeErrors=append(orphanVolumeErrors,fmt.Errorf("orphaned pod %q found, but error %v occurred during reading of volume-subpaths dir from disk",uid,err))
returnorphanVolumeErrors
}
iflen(subpathVolumePaths)>0{
for_,subpathVolumePath:=rangesubpathVolumePaths{
iferr:=syscall.Rmdir(subpathVolumePath);err!=nil{
orphanVolumeErrors=append(orphanVolumeErrors,fmt.Errorf("orphaned pod %q found, but failed to rmdir() subpath at path %v: %v",uid,subpathVolumePath,err))
}else{
klog.Warningf("Cleaned up orphaned volume subpath from pod %q at %s",uid,subpathVolumePath)
}
}
}
// Remove any remaining subdirectories along with the volumes directory itself.
// Call RemoveAllOneFilesystem for remaining subdirs under the pod directory
podDir:=kl.getPodDir(uid)
podSubdirs,err:=ioutil.ReadDir(podDir)
iferr!=nil{
orphanVolumeErrors=append(orphanVolumeErrors,fmt.Errorf("orphaned pod %q found, but error %v occurred during reading of volume-subpaths dir from disk",uid,err))
klog.Errorf("Could not read directory %q; err: %v",podDir,err)
orphanRemovalErrors=append(orphanRemovalErrors,fmt.Errorf("orphaned pod %q found, but error %v occurred during reading the pod dir from disk",uid,err))
continue
}
iflen(subpathVolumePaths)>0{
for_,subpathVolumePath:=rangesubpathVolumePaths{
iferr:=syscall.Rmdir(subpathVolumePath);err!=nil{
orphanVolumeErrors=append(orphanVolumeErrors,fmt.Errorf("orphaned pod %q found, but failed to rmdir() subpath at path %v: %v",uid,subpathVolumePath,err))
allVolumesCleanedUp=false
}else{
klog.Warningf("Cleaned up orphaned volume subpath from pod %q at %s",uid,subpathVolumePath)
klog.Errorf("Failed to remove orphaned pod %q subdir %q; err: %v",uid,podSubdirPath,err)
orphanRemovalErrors=append(orphanRemovalErrors,fmt.Errorf("orphaned pod %q found, but error %v occurred when trying to remove subdir %q",uid,err,podSubdirPath))
}
}
if!allVolumesCleanedUp{
// Not all volumes were removed, so don't clean up the pod directory yet. It is likely
// that there are still mountpoints left which could stall RemoveAllOneFilesystem which
// would otherwise be called below.
// Errors for all removal operations have already been recorded, so don't add another
// one here.
continue
}
// Rmdir the pod dir, which should be empty if everything above was successful
klog.V(3).Infof("Orphaned pod %q found, removing",uid)
orphanRemovalErrors=append(orphanRemovalErrors,fmt.Errorf("orphaned pod %q found, but error %v occurred when trying to remove the pod directory",uid,err))