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
d564d2e7
Commit
d564d2e7
authored
Apr 03, 2019
by
Vladimir Vivien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CSI - Prevents unsupported device mount with CanMountDevice(spec) check
parent
b13b2bb1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
1 deletion
+124
-1
BUILD
pkg/volume/csi/BUILD
+1
-0
csi_plugin.go
pkg/volume/csi/csi_plugin.go
+11
-1
csi_plugin_test.go
pkg/volume/csi/csi_plugin_test.go
+112
-0
csi_test.go
pkg/volume/csi/csi_test.go
+0
-0
No files found.
pkg/volume/csi/BUILD
View file @
d564d2e7
...
...
@@ -50,6 +50,7 @@ go_test(
"csi_drivers_store_test.go",
"csi_mounter_test.go",
"csi_plugin_test.go",
"csi_test.go",
"csi_util_test.go",
"expander_test.go",
],
...
...
pkg/volume/csi/csi_plugin.go
View file @
d564d2e7
...
...
@@ -607,8 +607,18 @@ func (p *csiPlugin) CanAttach(spec *volume.Spec) (bool, error) {
return
!
skipAttach
,
nil
}
//
TODO (#75352) add proper logic to determine device moutability by inspecting the spec.
//
CanDeviceMount returns true if the spec supports device mount
func
(
p
*
csiPlugin
)
CanDeviceMount
(
spec
*
volume
.
Spec
)
(
bool
,
error
)
{
driverMode
,
err
:=
p
.
getDriverMode
(
spec
)
if
err
!=
nil
{
return
false
,
err
}
if
driverMode
==
ephemeralDriverMode
{
klog
.
V
(
5
)
.
Info
(
log
(
"plugin.CanDeviceMount skipped ephemeral mode detected for spec %v"
,
spec
.
Name
()))
return
false
,
nil
}
return
true
,
nil
}
...
...
pkg/volume/csi/csi_plugin_test.go
View file @
d564d2e7
...
...
@@ -958,6 +958,118 @@ func TestPluginFindAttachablePlugin(t *testing.T) {
}
}
func
TestPluginCanDeviceMount
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIInlineVolume
,
true
)()
tests
:=
[]
struct
{
name
string
driverName
string
spec
*
volume
.
Spec
canDeviceMount
bool
shouldFail
bool
}{
{
name
:
"non device mountable inline"
,
driverName
:
"inline-driver"
,
spec
:
volume
.
NewSpecFromVolume
(
makeTestVol
(
"test-vol"
,
"inline-driver"
)),
canDeviceMount
:
false
,
},
{
name
:
"device mountable PV"
,
driverName
:
"device-mountable-pv"
,
spec
:
volume
.
NewSpecFromPersistentVolume
(
makeTestPV
(
"test-vol"
,
20
,
"device-mountable-pv"
,
testVol
),
true
),
canDeviceMount
:
true
,
},
{
name
:
"incomplete spec"
,
driverName
:
"device-unmountable"
,
spec
:
&
volume
.
Spec
{
ReadOnly
:
true
},
canDeviceMount
:
false
,
shouldFail
:
true
,
},
{
name
:
"missing spec"
,
driverName
:
"device-unmountable"
,
canDeviceMount
:
false
,
shouldFail
:
true
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
pluginCanDeviceMount
,
err
:=
plug
.
CanDeviceMount
(
test
.
spec
)
if
err
!=
nil
&&
!
test
.
shouldFail
{
t
.
Fatalf
(
"unexpected error in plug.CanDeviceMount: %s"
,
err
)
}
if
pluginCanDeviceMount
!=
test
.
canDeviceMount
{
t
.
Fatalf
(
"expecting plugin.CanAttach %t got %t"
,
test
.
canDeviceMount
,
pluginCanDeviceMount
)
}
})
}
}
func
TestPluginFindDeviceMountablePluginBySpec
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIInlineVolume
,
true
)()
tests
:=
[]
struct
{
name
string
driverName
string
spec
*
volume
.
Spec
canDeviceMount
bool
shouldFail
bool
}{
{
name
:
"non device mountable inline"
,
driverName
:
"inline-driver"
,
spec
:
volume
.
NewSpecFromVolume
(
makeTestVol
(
"test-vol"
,
"inline-driver"
)),
canDeviceMount
:
false
,
},
{
name
:
"device mountable PV"
,
driverName
:
"device-mountable-pv"
,
spec
:
volume
.
NewSpecFromPersistentVolume
(
makeTestPV
(
"test-vol"
,
20
,
"device-mountable-pv"
,
testVol
),
true
),
canDeviceMount
:
true
,
},
{
name
:
"incomplete spec"
,
driverName
:
"device-unmountable"
,
spec
:
&
volume
.
Spec
{
ReadOnly
:
true
},
canDeviceMount
:
false
,
shouldFail
:
true
,
},
{
name
:
"missing spec"
,
driverName
:
"device-unmountable"
,
canDeviceMount
:
false
,
shouldFail
:
true
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
utiltesting
.
MkTmpdir
(
"csi-test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't create temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
client
:=
fakeclient
.
NewSimpleClientset
()
host
:=
volumetest
.
NewFakeVolumeHost
(
tmpDir
,
client
,
nil
)
plugMgr
:=
&
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
nil
/* prober */
,
host
)
plug
,
err
:=
plugMgr
.
FindDeviceMountablePluginBySpec
(
test
.
spec
)
if
err
!=
nil
&&
!
test
.
shouldFail
{
t
.
Fatalf
(
"unexpected error in plugMgr.FindDeviceMountablePluginBySpec: %s"
,
err
)
}
if
(
plug
!=
nil
)
!=
test
.
canDeviceMount
{
t
.
Fatalf
(
"expecting deviceMountablePlugin, but got nil"
)
}
})
}
}
func
TestPluginNewBlockMapper
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
...
...
pkg/volume/csi/csi_test.go
0 → 100644
View file @
d564d2e7
This diff is collapsed.
Click to expand it.
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