From 0bcd11d4f23862842862ce27d1c2d1fb1823b0d5 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 23 Jun 2020 12:42:26 +0000 Subject: [PATCH] fix: append username if it's Azure File fix windows build failure --- pkg/smb/nodeserver.go | 15 ++++++++++++--- pkg/smb/smb_common_linux.go | 4 ++-- pkg/smb/smb_common_windows.go | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/smb/nodeserver.go b/pkg/smb/nodeserver.go index d7d81c0ae..c8bc8f7bc 100644 --- a/pkg/smb/nodeserver.go +++ b/pkg/smb/nodeserver.go @@ -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 }) diff --git a/pkg/smb/smb_common_linux.go b/pkg/smb/smb_common_linux.go index 5ef29f79e..46252c4ec 100644 --- a/pkg/smb/smb_common_linux.go +++ b/pkg/smb/smb_common_linux.go @@ -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) } diff --git a/pkg/smb/smb_common_windows.go b/pkg/smb/smb_common_windows.go index c3f8c6e68..641cc34f1 100644 --- a/pkg/smb/smb_common_windows.go +++ b/pkg/smb/smb_common_windows.go @@ -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 {