fix: append username if it's Azure File

fix windows build failure
This commit is contained in:
andyzhangx 2020-06-23 12:42:26 +00:00
parent 16e77a18ce
commit 0bcd11d4f2
3 changed files with 17 additions and 8 deletions

View File

@ -38,7 +38,8 @@ import (
)
const (
sourceField = "source"
sourceField = "source"
azureFileUserName = "AZURE"
)
// NodePublishVolume mount the volume from staging to target path
@ -159,7 +160,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
var mountOptions []string
if runtime.GOOS == "windows" {
mountOptions = []string{username, password}
if strings.Contains(source, ".file.core.") && !strings.HasPrefix(strings.ToUpper(username), azureFileUserName) {
// if mount source is Azure File Server, e.g.
// accountname.file.core.windows.net
// accountname.file.core.chinacloudapi.cn
// Add "AZURE\\" before username
mountOptions = []string{fmt.Sprintf("%s\\%s", azureFileUserName, username), password}
} else {
mountOptions = []string{username, password}
}
} else {
if err := os.MkdirAll(targetPath, 0750); err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("MkdirAll %s failed with error: %v", targetPath, err))
@ -185,7 +194,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
}
mountComplete := false
err = wait.Poll(5*time.Second, 10*time.Minute, func() (bool, error) {
err := SMBMount(d.mounter, source, targetPath, "cifs", mountOptions)
err := Mount(d.mounter, source, targetPath, "cifs", mountOptions)
mountComplete = true
return true, err
})

View File

@ -24,11 +24,11 @@ import (
"k8s.io/utils/mount"
)
func SMBMount(m *mount.SafeFormatAndMount, source, target, fsType string, options []string) error {
func Mount(m *mount.SafeFormatAndMount, source, target, fsType string, options []string) error {
return m.Mount(source, target, fsType, options)
}
func SMBUnmount(m *mount.SafeFormatAndMount, target string) error {
func Unmount(m *mount.SafeFormatAndMount, target string) error {
return m.Unmount(target)
}

View File

@ -26,7 +26,7 @@ import (
"k8s.io/utils/mount"
)
func SMBMount(m *mount.SafeFormatAndMount, source, target, fsType string, options []string) error {
func Mount(m *mount.SafeFormatAndMount, source, target, fsType string, options []string) error {
proxy, ok := m.Interface.(*mounter.CSIProxyMounter)
if !ok {
return fmt.Errorf("could not cast to csi proxy class")
@ -34,7 +34,7 @@ func SMBMount(m *mount.SafeFormatAndMount, source, target, fsType string, option
return proxy.SMBMount(source, target, fsType, options)
}
func SMBUnmount(m *mount.SafeFormatAndMount, target string) error {
func Unmount(m *mount.SafeFormatAndMount, target string) error {
proxy, ok := m.Interface.(*mounter.CSIProxyMounter)
if !ok {
return fmt.Errorf("could not cast to csi proxy class")
@ -54,7 +54,7 @@ func RemoveStageTarget(m *mount.SafeFormatAndMount, target string) error {
// The clean up mount point point calls is supposed for fix the corrupted directories as well.
// For alpha CSI proxy integration, we only do an unmount.
func CleanupSMBMountPoint(m *mount.SafeFormatAndMount, target string, extensiveMountCheck bool) error {
return SMBUnmount(m, target)
return Unmount(m, target)
}
func CleanupMountPoint(m *mount.SafeFormatAndMount, target string, extensiveMountCheck bool) error {