mirror of https://github.com/k3s-io/k3s
Merge pull request #53629 from andyzhangx/azurefile-improve
Automatic merge from submit-queue (batch tested with PRs 46341, 53629). 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>. fix azure file mount limit issue on windows due to using drive letter **What this PR does / why we need it**: It's not necessary to use drive letter in azure file mount, correct usage for New-SmbGlobalMapping is like following: ``` New-SmbGlobalMapping -RemotePath $AzureFilePath -Credential $Credential mklink /D $mountPath $AzureFilePath ``` I removed the `LocalPath` parameter in New-SmbGlobalMapping **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #54668 Without this PR, there is a limit(25) for azure file mount number on each node because only 25 drive letters could be used on each windows node, With this PR, there would be no such limit. **Special notes for your reviewer**: @PatrickLang **Release note**: ``` fix azure file mount limit issue on windows due to using drive letter ``` /sig azure /sig windowspull/6/head
commit
618b705a4b
|
@ -85,12 +85,8 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
|
|||
`$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord`,
|
||||
options[0], options[1])
|
||||
|
||||
driverLetter, err := getAvailableDriveLetter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bindSource = driverLetter + ":"
|
||||
cmdLine += fmt.Sprintf(";New-SmbGlobalMapping -LocalPath %s -RemotePath %s -Credential $Credential", bindSource, source)
|
||||
bindSource = source
|
||||
cmdLine += fmt.Sprintf(";New-SmbGlobalMapping -RemotePath %s -Credential $Credential", source)
|
||||
|
||||
if output, err := exec.Command("powershell", "/c", cmdLine).CombinedOutput(); err != nil {
|
||||
// we don't return error here, even though New-SmbGlobalMapping failed, we still make it successful,
|
||||
|
@ -298,20 +294,6 @@ func normalizeWindowsPath(path string) string {
|
|||
return normalizedPath
|
||||
}
|
||||
|
||||
func getAvailableDriveLetter() (string, error) {
|
||||
cmd := "$used = Get-PSDrive | Select-Object -Expand Name | Where-Object { $_.Length -eq 1 }"
|
||||
cmd += ";$drive = 67..90 | ForEach-Object { [string][char]$_ } | Where-Object { $used -notcontains $_ } | Select-Object -First 1;$drive"
|
||||
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getAvailableDriveLetter failed: %v, output: %q", err, string(output))
|
||||
}
|
||||
|
||||
if len(output) == 0 {
|
||||
return "", fmt.Errorf("azureMount: there is no available drive letter now")
|
||||
}
|
||||
return string(output)[:1], nil
|
||||
}
|
||||
|
||||
// ValidateDiskNumber : disk number should be a number in [0, 99]
|
||||
func ValidateDiskNumber(disk string) error {
|
||||
diskNum, err := strconv.Atoi(disk)
|
||||
|
|
|
@ -24,12 +24,6 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestGetAvailableDriveLetter(t *testing.T) {
|
||||
if _, err := getAvailableDriveLetter(); err != nil {
|
||||
t.Errorf("getAvailableDriveLetter test failed : %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeWindowsPath(t *testing.T) {
|
||||
path := `/var/lib/kubelet/pods/146f8428-83e7-11e7-8dd4-000d3a31dac4/volumes/kubernetes.io~azure-disk`
|
||||
normalizedPath := normalizeWindowsPath(path)
|
||||
|
|
Loading…
Reference in New Issue