Skip to content

Commit

Permalink
Merge pull request #57307 from andyzhangx/automated-cherry-pick-of-#5…
Browse files Browse the repository at this point in the history
…6921-upstream-release-1.8

Automatic merge from submit-queue.

Automated cherry pick of #56921

Cherry pick of #56921 on release-1.8.

#56921: enable flexvolume on Windows
  • Loading branch information
Kubernetes Submit Queue committed Dec 20, 2017
2 parents 24d0563 + 7a216c7 commit 4fd903a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/kubelet/volume_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package kubelet
import (
"fmt"
"net"
"runtime"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -74,7 +75,11 @@ type kubeletVolumeHost struct {
}

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) GetPodPluginDir(podUID types.UID, pluginName string) string {
Expand Down
7 changes: 6 additions & 1 deletion pkg/volume/flexvolume/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package flexvolume
import (
"fmt"
"path"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -97,7 +98,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.
Expand Down
9 changes: 9 additions & 0 deletions pkg/volume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,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
}
31 changes: 31 additions & 0 deletions pkg/volume/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,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)
}
}
}

0 comments on commit 4fd903a

Please sign in to comment.