// getPodVolumePathListFromDisk returns a list of the volume paths by reading the // volume directories for the given pod from the disk. 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) return volumes, err } for _, volumePluginDir := range volumePluginDirs { volumePluginName := volumePluginDir.Name() volumePluginPath := path.Join(podVolDir, volumePluginName) volumeDirs, err := util.ReadDirNoStat(volumePluginPath) if err != nil { return volumes, fmt.Errorf("Could not read directory %s: %v", volumePluginPath, err) } for _, volumeDir := range volumeDirs { volumes = append(volumes, path.Join(volumePluginPath, volumeDir)) } } return volumes, nil }
// getVolumesFromPodDir scans through the volumes directories under the given pod directory. // It returns a list of pod volume information including pod's uid, volume's plugin name, mount path, // and volume spec name. func getVolumesFromPodDir(podDir string) ([]podVolume, error) { podsDirInfo, err := ioutil.ReadDir(podDir) if err != nil { return nil, err } volumes := []podVolume{} for i := range podsDirInfo { if !podsDirInfo[i].IsDir() { continue } podName := podsDirInfo[i].Name() podDir := path.Join(podDir, podName) volumesDir := path.Join(podDir, options.DefaultKubeletVolumesDirName) volumesDirInfo, err := ioutil.ReadDir(volumesDir) if err != nil { glog.Errorf("Could not read volume directory %q: %v", volumesDir, err) continue } for _, volumeDir := range volumesDirInfo { pluginName := volumeDir.Name() volumePluginPath := path.Join(volumesDir, pluginName) volumePluginDirs, err := util.ReadDirNoStat(volumePluginPath) if err != nil { glog.Errorf("Could not read volume plugin directory %q: %v", volumePluginPath, err) continue } unescapePluginName := strings.UnescapeQualifiedNameForDisk(pluginName) for _, volumeName := range volumePluginDirs { mountPath := path.Join(volumePluginPath, volumeName) volumes = append(volumes, podVolume{ podName: volumetypes.UniquePodName(podName), volumeSpecName: volumeName, mountPath: mountPath, pluginName: unescapePluginName, }) } } } glog.V(10).Infof("Get volumes from pod directory %q %+v", podDir, volumes) return volumes, nil }
// getPodVolumeNameListFromDisk returns a list of the volume names by reading the // volume directories for the given pod from the disk. func (kl *Kubelet) getPodVolumeNameListFromDisk(podUID types.UID) ([]string, error) { volumes := []string{} podVolDir := kl.getPodVolumesDir(podUID) volumePluginDirs, err := ioutil.ReadDir(podVolDir) if err != nil { glog.Errorf("Could not read directory %s: %v", podVolDir, err) return volumes, err } for _, volumePluginDir := range volumePluginDirs { volumePluginName := volumePluginDir.Name() volumePluginPath := path.Join(podVolDir, volumePluginName) volumeDirs, err := util.ReadDirNoStat(volumePluginPath) if err != nil { return volumes, err } volumes = append(volumes, volumeDirs...) } return volumes, nil }