mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
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:
parent
7f528c67ca
commit
e0edfebe82
@ -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"
|
||||
@ -193,6 +194,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.
|
||||
|
Loading…
Reference in New Issue
Block a user