mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Broaden scope of host path types to skip processing in Windows
Signed-off-by: Deep Debroy <ddebroy@docker.com>
This commit is contained in:
parent
b4bb5dd430
commit
f8a69f1086
@ -215,15 +215,16 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker Volume Mounts fail on Windows if it is not of the form C:/ nor a named pipe starting with \\.\pipe\
|
// Docker Volume Mounts fail on Windows if it is not of the form C:/
|
||||||
containerPath := mount.MountPath
|
containerPath := mount.MountPath
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
if !volumeutil.IsWindowsNamedPipe(runtime.GOOS, hostPath) && (strings.HasPrefix(hostPath, "/") || strings.HasPrefix(hostPath, "\\")) && !strings.Contains(hostPath, ":") {
|
// Append C: only if it looks like a local path. Do not process UNC path/SMB shares/named pipes
|
||||||
|
if (strings.HasPrefix(hostPath, "/") || strings.HasPrefix(hostPath, "\\")) && !strings.Contains(hostPath, ":") && !volumeutil.IsWindowsUNCPath(runtime.GOOS, hostPath) {
|
||||||
hostPath = "c:" + hostPath
|
hostPath = "c:" + hostPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// IsAbs returns false for named pipes (\\.\pipe\...) in Windows. So check for it specifically and skip MakeAbsolutePath
|
// IsAbs returns false for UNC path/SMB shares/named pipes in Windows. So check for those specifically and skip MakeAbsolutePath
|
||||||
if !volumeutil.IsWindowsNamedPipe(runtime.GOOS, containerPath) && !filepath.IsAbs(containerPath) {
|
if !volumeutil.IsWindowsUNCPath(runtime.GOOS, containerPath) && !filepath.IsAbs(containerPath) {
|
||||||
containerPath = volumeutil.MakeAbsolutePath(runtime.GOOS, containerPath)
|
containerPath = volumeutil.MakeAbsolutePath(runtime.GOOS, containerPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,8 +945,15 @@ func CheckPersistentVolumeClaimModeBlock(pvc *v1.PersistentVolumeClaim) bool {
|
|||||||
return utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && pvc.Spec.VolumeMode != nil && *pvc.Spec.VolumeMode == v1.PersistentVolumeBlock
|
return utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && pvc.Spec.VolumeMode != nil && *pvc.Spec.VolumeMode == v1.PersistentVolumeBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsWindowsNamedPipe(goos, path string) bool {
|
// IsWindowsUNCPath checks if path is prefixed with \\
|
||||||
if goos == "windows" && strings.HasPrefix(path, `\\.\pipe\`) {
|
// This can be used to skip any processing of paths
|
||||||
|
// that point to SMB shares, local named pipes and local UNC path
|
||||||
|
func IsWindowsUNCPath(goos, path string) bool {
|
||||||
|
if goos != "windows" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Check for UNC prefix \\
|
||||||
|
if strings.HasPrefix(path, `\\`) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -2373,43 +2373,53 @@ func TestGetWindowsPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsWindowsNamedPipe(t *testing.T) {
|
func TestIsWindowsUNCPath(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
goos string
|
goos string
|
||||||
path string
|
path string
|
||||||
isNamedPipe bool
|
isUNCPath bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
goos: "linux",
|
goos: "linux",
|
||||||
path: `/usr/bin`,
|
path: `/usr/bin`,
|
||||||
isNamedPipe: false,
|
isUNCPath: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
goos: "linux",
|
goos: "linux",
|
||||||
path: `\\.\pipe\foo`,
|
path: `\\.\pipe\foo`,
|
||||||
isNamedPipe: false,
|
isUNCPath: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
goos: "windows",
|
goos: "windows",
|
||||||
path: `C:\foo`,
|
path: `C:\foo`,
|
||||||
isNamedPipe: false,
|
isUNCPath: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
goos: "windows",
|
goos: "windows",
|
||||||
path: `\\.\invalid`,
|
path: `\\server\share\foo`,
|
||||||
isNamedPipe: false,
|
isUNCPath: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
goos: "windows",
|
goos: "windows",
|
||||||
path: `\\.\pipe\valid_pipe`,
|
path: `\\?\server\share`,
|
||||||
isNamedPipe: true,
|
isUNCPath: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
goos: "windows",
|
||||||
|
path: `\\?\c:\`,
|
||||||
|
isUNCPath: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
goos: "windows",
|
||||||
|
path: `\\.\pipe\valid_pipe`,
|
||||||
|
isUNCPath: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
result := IsWindowsNamedPipe(test.goos, test.path)
|
result := IsWindowsUNCPath(test.goos, test.path)
|
||||||
if result != test.isNamedPipe {
|
if result != test.isUNCPath {
|
||||||
t.Errorf("IsWindowsNamedPipe(%v) returned (%v), expected (%v)", test.path, result, test.isNamedPipe)
|
t.Errorf("IsWindowsUNCPath(%v) returned (%v), expected (%v)", test.path, result, test.isUNCPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user