From b3c45247bc0562cb3bbba0791e58f0b5b3bfad9e Mon Sep 17 00:00:00 2001 From: jayunit100 Date: Tue, 25 Apr 2017 20:36:09 -0400 Subject: [PATCH] Cleanup orphan logging that goes on in the sync loop. --- pkg/kubelet/kubelet_volumes.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/kubelet_volumes.go b/pkg/kubelet/kubelet_volumes.go index 10bcee9f0be..32b952b0364 100644 --- a/pkg/kubelet/kubelet_volumes.go +++ b/pkg/kubelet/kubelet_volumes.go @@ -78,7 +78,7 @@ func (kl *Kubelet) newVolumeMounterFromPlugins(spec *volume.Spec, pod *v1.Pod, o } // cleanupOrphanedPodDirs removes the volumes of pods that should not be -// running and that have no containers running. +// running and that have no containers running. Note that we roll up logs here since it runs in the main loop. func (kl *Kubelet) cleanupOrphanedPodDirs( pods []*v1.Pod, runningPods []*kubecontainer.Pod) error { allPods := sets.NewString() @@ -93,7 +93,10 @@ func (kl *Kubelet) cleanupOrphanedPodDirs( if err != nil { return err } - errlist := []error{} + + orphanRemovalErrors := []error{} + orphanVolumeErrors := []error{} + for _, uid := range found { if allPods.Has(string(uid)) { continue @@ -107,18 +110,29 @@ func (kl *Kubelet) cleanupOrphanedPodDirs( // If there are still volume directories, do not delete directory volumePaths, err := kl.getPodVolumePathListFromDisk(uid) if err != nil { - glog.Errorf("Orphaned pod %q found, but error %v occurred during reading volume dir from disk", uid, err) + orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("Orphaned pod %q found, but error %v occurred during reading volume dir from disk", uid, err)) continue } if len(volumePaths) > 0 { - glog.Errorf("Orphaned pod %q found, but volume paths are still present on disk.", uid) + orphanVolumeErrors = append(orphanVolumeErrors, fmt.Errorf("Orphaned pod %q found, but volume paths are still present on disk.", uid)) continue } glog.V(3).Infof("Orphaned pod %q found, removing", uid) if err := removeall.RemoveAllOneFilesystem(kl.mounter, kl.getPodDir(uid)); err != nil { glog.Errorf("Failed to remove orphaned pod %q dir; err: %v", uid, err) - errlist = append(errlist, err) + orphanRemovalErrors = append(orphanRemovalErrors, err) } } - return utilerrors.NewAggregate(errlist) + + logSpew := func(errs []error) { + if len(errs) > 0 { + glog.Errorf("%v : There were a total of %v errors similar to this. Turn up verbosity to see them.", errs[0], len(errs)) + for _, err := range errs { + glog.V(5).Infof("Orphan pod: %v", err) + } + } + } + logSpew(orphanVolumeErrors) + logSpew(orphanRemovalErrors) + return utilerrors.NewAggregate(orphanRemovalErrors) }