Unverified Commit ea55d70e authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #56921 from andyzhangx/flexvolume-windows

Automatic merge from submit-queue (batch tested with PRs 56650, 55813, 56911, 56921, 56871). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. enable flexvolume on Windows node **What this PR does / why we need it**: enable flexvolume on Windows node: current PodVolumeDir is like `\var\lib\kubelet\pods\f54c5a74-da63-11e7-b71a-000d3a02c330\volumes\test~hostpath.cmd\flextest` which is a unix path, with this PR, PodVolumeDir in **windows** kubelet will be converted into like `c:\var\lib\kubelet\pods\f54c5a74-da63-11e7-b71a-000d3a02c330\volumes\test~hostpath.cmd\flextest` **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #56875 **Special notes for your reviewer**: Detailed steps about how to use flexvolume on Windows with this PR: https://github.com/andyzhangx/Demo/tree/master/windows/flexvolume **Release note**: ``` enable flexvolume on Windows node ``` /sig windows
parents a9029595 5c7a1a2c
......@@ -19,6 +19,7 @@ package kubelet
import (
"fmt"
"net"
"runtime"
"github.com/golang/glog"
......@@ -91,7 +92,11 @@ func (kvh *kubeletVolumeHost) GetVolumeDevicePluginDir(pluginName string) string
}
func (kvh *kubeletVolumeHost) GetPodVolumeDir(podUID types.UID, pluginName string, volumeName string) string {
return kvh.kubelet.getPodVolumeDir(podUID, pluginName, volumeName)
dir := kvh.kubelet.getPodVolumeDir(podUID, pluginName, volumeName)
if runtime.GOOS == "windows" {
dir = volume.GetWindowsPath(dir)
}
return dir
}
func (kvh *kubeletVolumeHost) GetPodVolumeDeviceDir(podUID types.UID, pluginName string) string {
......
......@@ -19,6 +19,7 @@ package flexvolume
import (
"fmt"
"path"
"runtime"
"strings"
"sync"
......@@ -100,7 +101,11 @@ func (plugin *flexVolumePlugin) Init(host volume.VolumeHost) error {
func (plugin *flexVolumePlugin) getExecutable() string {
parts := strings.Split(plugin.driverName, "/")
execName := parts[len(parts)-1]
return path.Join(plugin.execPath, execName)
execPath := path.Join(plugin.execPath, execName)
if runtime.GOOS == "windows" {
execPath = volume.GetWindowsPath(execPath)
}
return execPath
}
// Name is part of the volume.VolumePlugin interface.
......
......@@ -514,3 +514,12 @@ func AccessModesContainedInAll(indexedModes []v1.PersistentVolumeAccessMode, req
}
return true
}
// GetWindowsPath get a windows path
func GetWindowsPath(path string) string {
windowsPath := strings.Replace(path, "/", "\\", -1)
if strings.HasPrefix(windowsPath, "\\") {
windowsPath = "c:" + windowsPath
}
return windowsPath
}
......@@ -869,3 +869,34 @@ func TestValidateZone(t *testing.T) {
}
}
}
func TestGetWindowsPath(t *testing.T) {
tests := []struct {
path string
expectedPath string
}{
{
path: `/var/lib/kubelet/pods/146f8428-83e7-11e7-8dd4-000d3a31dac4/volumes/kubernetes.io~disk`,
expectedPath: `c:\var\lib\kubelet\pods\146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~disk`,
},
{
path: `\var/lib/kubelet/pods/146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~disk`,
expectedPath: `c:\var\lib\kubelet\pods\146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~disk`,
},
{
path: `/`,
expectedPath: `c:\`,
},
{
path: ``,
expectedPath: ``,
},
}
for _, test := range tests {
result := GetWindowsPath(test.path)
if result != test.expectedPath {
t.Errorf("GetWindowsPath(%v) returned (%v), want (%v)", test.path, result, test.expectedPath)
}
}
}
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