From f87d9fa14cd76e58b8452d4e71e5c5818ab9df84 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Fri, 16 Dec 2016 15:03:50 -0800 Subject: [PATCH] Add path exist check in getPodVolumePathListFromDisk Add the path exist check in the function. If the path does not exist, return empty list and nil error. --- pkg/kubelet/kubelet_getters.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/kubelet/kubelet_getters.go b/pkg/kubelet/kubelet_getters.go index a2da9cf0d1b79..35c0907374f2d 100644 --- a/pkg/kubelet/kubelet_getters.go +++ b/pkg/kubelet/kubelet_getters.go @@ -30,6 +30,7 @@ import ( "k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/util" nodeutil "k8s.io/kubernetes/pkg/util/node" + volumeutil "k8s.io/kubernetes/pkg/volume/util" ) // getRootDir returns the full path to the directory under which kubelet can @@ -244,6 +245,14 @@ func (kl *Kubelet) GetExtraSupplementalGroupsForPod(pod *api.Pod) []int64 { func (kl *Kubelet) getPodVolumePathListFromDisk(podUID types.UID) ([]string, error) { volumes := []string{} podVolDir := kl.getPodVolumesDir(podUID) + + if pathExists, pathErr := volumeutil.PathExists(podVolDir); pathErr != nil { + return volumes, fmt.Errorf("Error checking if path %q exists: %v", podVolDir, pathErr) + } else if !pathExists { + glog.Warningf("Warning: path %q does not exist: %q", podVolDir) + return volumes, nil + } + volumePluginDirs, err := ioutil.ReadDir(podVolDir) if err != nil { glog.Errorf("Could not read directory %s: %v", podVolDir, err)