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
48212913
Unverified
Commit
48212913
authored
Nov 16, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71095 from msau42/csi-devicepath
Remove devicePath dependency for CSI volumes
parents
f877b225
974d47ec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
1 deletion
+71
-1
csi_attacher.go
pkg/volume/csi/csi_attacher.go
+4
-1
csi_attacher_test.go
pkg/volume/csi/csi_attacher_test.go
+67
-0
No files found.
pkg/volume/csi/csi_attacher.go
View file @
48212913
...
@@ -119,16 +119,19 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
...
@@ -119,16 +119,19 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
klog
.
V
(
4
)
.
Info
(
log
(
"attacher.Attach finished OK with VolumeAttachment object [%s]"
,
attachID
))
klog
.
V
(
4
)
.
Info
(
log
(
"attacher.Attach finished OK with VolumeAttachment object [%s]"
,
attachID
))
// TODO(71164): In 1.15, return empty devicePath
return
attachID
,
nil
return
attachID
,
nil
}
}
func
(
c
*
csiAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
attachID
string
,
pod
*
v1
.
Pod
,
timeout
time
.
Duration
)
(
string
,
error
)
{
func
(
c
*
csiAttacher
)
WaitForAttach
(
spec
*
volume
.
Spec
,
_
string
,
pod
*
v1
.
Pod
,
timeout
time
.
Duration
)
(
string
,
error
)
{
source
,
err
:=
getCSISourceFromSpec
(
spec
)
source
,
err
:=
getCSISourceFromSpec
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"attacher.WaitForAttach failed to extract CSI volume source: %v"
,
err
))
klog
.
Error
(
log
(
"attacher.WaitForAttach failed to extract CSI volume source: %v"
,
err
))
return
""
,
err
return
""
,
err
}
}
attachID
:=
getAttachmentName
(
source
.
VolumeHandle
,
source
.
Driver
,
string
(
c
.
plugin
.
host
.
GetNodeName
()))
skip
,
err
:=
c
.
plugin
.
skipAttach
(
source
.
Driver
)
skip
,
err
:=
c
.
plugin
.
skipAttach
(
source
.
Driver
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"attacher.Attach failed to find if driver is attachable: %v"
,
err
))
klog
.
Error
(
log
(
"attacher.Attach failed to find if driver is attachable: %v"
,
err
))
...
...
pkg/volume/csi/csi_attacher_test.go
View file @
48212913
...
@@ -332,6 +332,73 @@ func TestAttacherWaitForVolumeAttachmentWithCSIDriver(t *testing.T) {
...
@@ -332,6 +332,73 @@ func TestAttacherWaitForVolumeAttachmentWithCSIDriver(t *testing.T) {
}
}
}
}
func
TestAttacherWaitForAttach
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
driver
string
makeAttachment
func
()
*
storage
.
VolumeAttachment
expectedAttachID
string
expectError
bool
}{
{
name
:
"successful attach"
,
driver
:
"attachable"
,
makeAttachment
:
func
()
*
storage
.
VolumeAttachment
{
testAttachID
:=
getAttachmentName
(
"test-vol"
,
"attachable"
,
"node"
)
successfulAttachment
:=
makeTestAttachment
(
testAttachID
,
"node"
,
"test-pv"
)
successfulAttachment
.
Status
.
Attached
=
true
return
successfulAttachment
},
expectedAttachID
:
getAttachmentName
(
"test-vol"
,
"attachable"
,
"node"
),
expectError
:
false
,
},
{
name
:
"failed attach"
,
driver
:
"attachable"
,
expectError
:
true
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
plug
,
_
,
tmpDir
,
_
:=
newTestWatchPlugin
(
t
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
attacher
,
err
:=
plug
.
NewAttacher
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create new attacher: %v"
,
err
)
}
csiAttacher
:=
attacher
.
(
*
csiAttacher
)
spec
:=
volume
.
NewSpecFromPersistentVolume
(
makeTestPV
(
"test-pv"
,
10
,
test
.
driver
,
"test-vol"
),
false
)
if
test
.
makeAttachment
!=
nil
{
attachment
:=
test
.
makeAttachment
()
_
,
err
=
csiAttacher
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Create
(
attachment
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create VolumeAttachment: %v"
,
err
)
}
gotAttachment
,
err
:=
csiAttacher
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachment
.
Name
,
meta
.
GetOptions
{})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to get created VolumeAttachment: %v"
,
err
)
}
t
.
Logf
(
"created test VolumeAttachment %+v"
,
gotAttachment
)
}
attachID
,
err
:=
csiAttacher
.
WaitForAttach
(
spec
,
""
,
nil
,
time
.
Second
)
if
err
!=
nil
&&
!
test
.
expectError
{
t
.
Errorf
(
"Unexpected error: %s"
,
err
)
}
if
err
==
nil
&&
test
.
expectError
{
t
.
Errorf
(
"Expected error, got none"
)
}
if
attachID
!=
test
.
expectedAttachID
{
t
.
Errorf
(
"Expected attachID %q, got %q"
,
test
.
expectedAttachID
,
attachID
)
}
})
}
}
func
TestAttacherWaitForVolumeAttachment
(
t
*
testing
.
T
)
{
func
TestAttacherWaitForVolumeAttachment
(
t
*
testing
.
T
)
{
nodeName
:=
"test-node"
nodeName
:=
"test-node"
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
...
...
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