Verify volume.GetPath() never returns ""
Add a new helper method volume.GetPath(Mounter) instead of calling the GetPath() of the Mounter directly. Check if GetPath() is returning a "" and convert that into an error. At this point, we only have information about the type of the Mounter, so let's log that if there is a problem Fixes #23163
This commit is contained in:
		@@ -1012,7 +1012,11 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
 | 
				
			|||||||
	for _, vol := range volumes {
 | 
						for _, vol := range volumes {
 | 
				
			||||||
		if vol.Mounter.GetAttributes().Managed && vol.Mounter.GetAttributes().SupportsSELinux {
 | 
							if vol.Mounter.GetAttributes().Managed && vol.Mounter.GetAttributes().SupportsSELinux {
 | 
				
			||||||
			// Relabel the volume and its content to match the 'Level' of the pod
 | 
								// Relabel the volume and its content to match the 'Level' of the pod
 | 
				
			||||||
			err := filepath.Walk(vol.Mounter.GetPath(), func(path string, info os.FileInfo, err error) error {
 | 
								path, err := volume.GetPath(vol.Mounter)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -1053,7 +1057,10 @@ func makeMounts(pod *api.Pod, podDir string, container *api.Container, hostName,
 | 
				
			|||||||
			vol.SELinuxLabeled = true
 | 
								vol.SELinuxLabeled = true
 | 
				
			||||||
			relabelVolume = true
 | 
								relabelVolume = true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		hostPath := vol.Mounter.GetPath()
 | 
							hostPath, err := volume.GetPath(vol.Mounter)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if mount.SubPath != "" {
 | 
							if mount.SubPath != "" {
 | 
				
			||||||
			hostPath = filepath.Join(hostPath, mount.SubPath)
 | 
								hostPath = filepath.Join(hostPath, mount.SubPath)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,7 @@ package volume
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
@@ -193,6 +194,15 @@ func GenerateVolumeName(clusterName, pvName string, maxLength int) string {
 | 
				
			|||||||
	return prefix + "-" + pvName
 | 
						return prefix + "-" + pvName
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Check if the path from the mounter is empty.
 | 
				
			||||||
 | 
					func GetPath(mounter Mounter) (string, error) {
 | 
				
			||||||
 | 
						path := mounter.GetPath()
 | 
				
			||||||
 | 
						if path == "" {
 | 
				
			||||||
 | 
							return "", fmt.Errorf("Path is empty %s", reflect.TypeOf(mounter).String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return path, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ChooseZone implements our heuristics for choosing a zone for volume creation based on the volume name
 | 
					// ChooseZone implements our heuristics for choosing a zone for volume creation based on the volume name
 | 
				
			||||||
// Volumes are generally round-robin-ed across all active zones, using the hash of the PVC Name.
 | 
					// Volumes are generally round-robin-ed across all active zones, using the hash of the PVC Name.
 | 
				
			||||||
// However, if the PVCName ends with `-<integer>`, we will hash the prefix, and then add the integer to the hash.
 | 
					// However, if the PVCName ends with `-<integer>`, we will hash the prefix, and then add the integer to the hash.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user