Commit 94905bd7 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #29619 from dims/fix-issue-23163

Automatic merge from submit-queue 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. Fixes #23163
parents 23eee2d7 e0edfebe
......@@ -1012,7 +1012,11 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
for _, vol := range volumes {
if vol.Mounter.GetAttributes().Managed && vol.Mounter.GetAttributes().SupportsSELinux {
// 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 {
return err
}
......@@ -1053,7 +1057,10 @@ func makeMounts(pod *api.Pod, podDir string, container *api.Container, hostName,
vol.SELinuxLabeled = true
relabelVolume = true
}
hostPath := vol.Mounter.GetPath()
hostPath, err := volume.GetPath(vol.Mounter)
if err != nil {
return nil, err
}
if mount.SubPath != "" {
hostPath = filepath.Join(hostPath, mount.SubPath)
}
......
......@@ -18,6 +18,7 @@ package volume
import (
"fmt"
"reflect"
"time"
"k8s.io/kubernetes/pkg/api"
......@@ -194,6 +195,15 @@ func GenerateVolumeName(clusterName, pvName string, maxLength int) string {
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
// 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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment