mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Merge pull request #123052 from jsafrane/clean-file-subpath
Fix cleanup of file subpaths
This commit is contained in:
commit
77775d4546
@ -116,7 +116,8 @@ func (kl *Kubelet) newVolumeMounterFromPlugins(spec *volume.Spec, pod *v1.Pod, o
|
|||||||
// removeOrphanedPodVolumeDirs attempts to remove the pod volumes directory and
|
// removeOrphanedPodVolumeDirs attempts to remove the pod volumes directory and
|
||||||
// its subdirectories. There should be no files left under normal conditions
|
// its subdirectories. There should be no files left under normal conditions
|
||||||
// when this is called, so it effectively does a recursive rmdir instead of
|
// when this is called, so it effectively does a recursive rmdir instead of
|
||||||
// RemoveAll to ensure it only removes directories and not regular files.
|
// RemoveAll to ensure it only removes empty directories and files that were
|
||||||
|
// used as mount points, but not content of the mount points.
|
||||||
func (kl *Kubelet) removeOrphanedPodVolumeDirs(uid types.UID) []error {
|
func (kl *Kubelet) removeOrphanedPodVolumeDirs(uid types.UID) []error {
|
||||||
orphanVolumeErrors := []error{}
|
orphanVolumeErrors := []error{}
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ func (kl *Kubelet) removeOrphanedPodVolumeDirs(uid types.UID) []error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are any volume-subpaths, attempt to rmdir them
|
// If there are any volume-subpaths, attempt to remove them
|
||||||
subpathVolumePaths, err := kl.getPodVolumeSubpathListFromDisk(uid)
|
subpathVolumePaths, err := kl.getPodVolumeSubpathListFromDisk(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("orphaned pod %q found, but error occurred during reading of volume-subpaths dir from disk: %v", uid, err))
|
orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("orphaned pod %q found, but error occurred during reading of volume-subpaths dir from disk: %v", uid, err))
|
||||||
@ -144,7 +145,8 @@ func (kl *Kubelet) removeOrphanedPodVolumeDirs(uid types.UID) []error {
|
|||||||
}
|
}
|
||||||
if len(subpathVolumePaths) > 0 {
|
if len(subpathVolumePaths) > 0 {
|
||||||
for _, subpathVolumePath := range subpathVolumePaths {
|
for _, subpathVolumePath := range subpathVolumePaths {
|
||||||
if err := syscall.Rmdir(subpathVolumePath); err != nil {
|
// 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 rmdir() subpath at path %v: %v", uid, subpathVolumePath, err))
|
||||||
} else {
|
} else {
|
||||||
klog.InfoS("Cleaned up orphaned volume subpath from pod", "podUID", uid, "path", subpathVolumePath)
|
klog.InfoS("Cleaned up orphaned volume subpath from pod", "podUID", uid, "path", subpathVolumePath)
|
||||||
|
Loading…
Reference in New Issue
Block a user