Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3abb9f0a
Unverified
Commit
3abb9f0a
authored
Oct 24, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70002 from andyzhangx/getdisklun
fix azure disk attachment error on Linux
parents
553a169d
f6906875
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
8 deletions
+96
-8
attacher.go
pkg/volume/azure_dd/attacher.go
+15
-8
azure_common.go
pkg/volume/azure_dd/azure_common.go
+26
-0
azure_common_test.go
pkg/volume/azure_dd/azure_common_test.go
+55
-0
No files found.
pkg/volume/azure_dd/attacher.go
View file @
3abb9f0a
...
...
@@ -152,8 +152,6 @@ func (a *azureDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName ty
}
func
(
a
*
azureDiskAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
devicePath
string
,
_
*
v1
.
Pod
,
timeout
time
.
Duration
)
(
string
,
error
)
{
var
err
error
volumeSource
,
_
,
err
:=
getVolumeSource
(
spec
)
if
err
!=
nil
{
return
""
,
err
...
...
@@ -167,13 +165,22 @@ func (a *azureDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string,
nodeName
:=
types
.
NodeName
(
a
.
plugin
.
host
.
GetHostName
())
diskName
:=
volumeSource
.
DiskName
glog
.
V
(
2
)
.
Infof
(
"azureDisk - WaitForAttach: begin to GetDiskLun by diskName(%s), DataDiskURI(%s), nodeName(%s), devicePath(%s)"
,
diskName
,
volumeSource
.
DataDiskURI
,
nodeName
,
devicePath
)
lun
,
err
:=
diskController
.
GetDiskLun
(
diskName
,
volumeSource
.
DataDiskURI
,
nodeName
)
if
err
!=
nil
{
return
""
,
err
var
lun
int32
if
runtime
.
GOOS
==
"windows"
{
glog
.
V
(
2
)
.
Infof
(
"azureDisk - WaitForAttach: begin to GetDiskLun by diskName(%s), DataDiskURI(%s), nodeName(%s), devicePath(%s)"
,
diskName
,
volumeSource
.
DataDiskURI
,
nodeName
,
devicePath
)
lun
,
err
=
diskController
.
GetDiskLun
(
diskName
,
volumeSource
.
DataDiskURI
,
nodeName
)
if
err
!=
nil
{
return
""
,
err
}
glog
.
V
(
2
)
.
Infof
(
"azureDisk - WaitForAttach: GetDiskLun succeeded, got lun(%v)"
,
lun
)
}
else
{
lun
,
err
=
getDiskLUN
(
devicePath
)
if
err
!=
nil
{
return
""
,
err
}
}
glog
.
V
(
2
)
.
Infof
(
"azureDisk - WaitForAttach: GetDiskLun succeeded, got lun(%v)"
,
lun
)
exec
:=
a
.
plugin
.
host
.
GetExec
(
a
.
plugin
.
GetPluginName
())
io
:=
&
osIOHandler
{}
...
...
pkg/volume/azure_dd/azure_common.go
View file @
3abb9f0a
...
...
@@ -21,6 +21,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
libstrings
"strings"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-07-01/storage"
...
...
@@ -59,6 +61,8 @@ var (
string
(
api
.
AzureSharedBlobDisk
),
string
(
api
.
AzureDedicatedBlobDisk
),
string
(
api
.
AzureManagedDisk
))
lunPathRE
=
regexp
.
MustCompile
(
`/dev/disk/azure/scsi(?:.*)/lun(.+)`
)
)
func
getPath
(
uid
types
.
UID
,
volName
string
,
host
volume
.
VolumeHost
)
string
{
...
...
@@ -201,3 +205,25 @@ func strFirstLetterToUpper(str string) string {
}
return
libstrings
.
ToUpper
(
string
(
str
[
0
]))
+
str
[
1
:
]
}
// getDiskLUN : deviceInfo could be a LUN number or a device path, e.g. /dev/disk/azure/scsi1/lun2
func
getDiskLUN
(
deviceInfo
string
)
(
int32
,
error
)
{
var
diskLUN
string
if
len
(
deviceInfo
)
<=
2
{
diskLUN
=
deviceInfo
}
else
{
// extract the LUN num from a device path
matches
:=
lunPathRE
.
FindStringSubmatch
(
deviceInfo
)
if
len
(
matches
)
==
2
{
diskLUN
=
matches
[
1
]
}
else
{
return
-
1
,
fmt
.
Errorf
(
"cannot parse deviceInfo: %s"
,
deviceInfo
)
}
}
lun
,
err
:=
strconv
.
Atoi
(
diskLUN
)
if
err
!=
nil
{
return
-
1
,
err
}
return
int32
(
lun
),
nil
}
pkg/volume/azure_dd/azure_common_test.go
View file @
3abb9f0a
...
...
@@ -187,3 +187,58 @@ func TestNormalizeStorageAccountType(t *testing.T) {
assert
.
Equal
(
t
,
err
!=
nil
,
test
.
expectError
,
fmt
.
Sprintf
(
"error msg: %v"
,
err
))
}
}
func
TestGetDiskLUN
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
deviceInfo
string
expectedLUN
int32
expectError
bool
}{
{
deviceInfo
:
"0"
,
expectedLUN
:
0
,
expectError
:
false
,
},
{
deviceInfo
:
"10"
,
expectedLUN
:
10
,
expectError
:
false
,
},
{
deviceInfo
:
"11d"
,
expectedLUN
:
-
1
,
expectError
:
true
,
},
{
deviceInfo
:
"999"
,
expectedLUN
:
-
1
,
expectError
:
true
,
},
{
deviceInfo
:
""
,
expectedLUN
:
-
1
,
expectError
:
true
,
},
{
deviceInfo
:
"/dev/disk/azure/scsi1/lun2"
,
expectedLUN
:
2
,
expectError
:
false
,
},
{
deviceInfo
:
"/dev/disk/azure/scsi0/lun12"
,
expectedLUN
:
12
,
expectError
:
false
,
},
{
deviceInfo
:
"/dev/disk/by-id/scsi1/lun2"
,
expectedLUN
:
-
1
,
expectError
:
true
,
},
}
for
_
,
test
:=
range
tests
{
result
,
err
:=
getDiskLUN
(
test
.
deviceInfo
)
assert
.
Equal
(
t
,
result
,
test
.
expectedLUN
)
assert
.
Equal
(
t
,
err
!=
nil
,
test
.
expectError
,
fmt
.
Sprintf
(
"error msg: %v"
,
err
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment