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
f7338373
Commit
f7338373
authored
Oct 03, 2018
by
lichuqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support mount options in setup
parent
2f4be20f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
16 deletions
+47
-16
local.go
pkg/volume/local/local.go
+6
-3
local_test.go
pkg/volume/local/local_test.go
+41
-13
No files found.
pkg/volume/local/local.go
View file @
f7338373
...
@@ -130,7 +130,8 @@ func (plugin *localVolumePlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ vo
...
@@ -130,7 +130,8 @@ func (plugin *localVolumePlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ vo
globalPath
:
globalLocalPath
,
globalPath
:
globalLocalPath
,
MetricsProvider
:
volume
.
NewMetricsStatFS
(
plugin
.
host
.
GetPodVolumeDir
(
pod
.
UID
,
stringsutil
.
EscapeQualifiedNameForDisk
(
localVolumePluginName
),
spec
.
Name
())),
MetricsProvider
:
volume
.
NewMetricsStatFS
(
plugin
.
host
.
GetPodVolumeDir
(
pod
.
UID
,
stringsutil
.
EscapeQualifiedNameForDisk
(
localVolumePluginName
),
spec
.
Name
())),
},
},
readOnly
:
readOnly
,
mountOptions
:
util
.
MountOptionFromSpec
(
spec
),
readOnly
:
readOnly
,
},
nil
},
nil
}
}
...
@@ -393,7 +394,8 @@ func (l *localVolume) GetPath() string {
...
@@ -393,7 +394,8 @@ func (l *localVolume) GetPath() string {
type
localVolumeMounter
struct
{
type
localVolumeMounter
struct
{
*
localVolume
*
localVolume
readOnly
bool
readOnly
bool
mountOptions
[]
string
}
}
var
_
volume
.
Mounter
=
&
localVolumeMounter
{}
var
_
volume
.
Mounter
=
&
localVolumeMounter
{}
...
@@ -476,10 +478,11 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -476,10 +478,11 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
if
m
.
readOnly
{
if
m
.
readOnly
{
options
=
append
(
options
,
"ro"
)
options
=
append
(
options
,
"ro"
)
}
}
mountOptions
:=
util
.
JoinMountOptions
(
options
,
m
.
mountOptions
)
glog
.
V
(
4
)
.
Infof
(
"attempting to mount %s"
,
dir
)
glog
.
V
(
4
)
.
Infof
(
"attempting to mount %s"
,
dir
)
globalPath
:=
util
.
MakeAbsolutePath
(
runtime
.
GOOS
,
m
.
globalPath
)
globalPath
:=
util
.
MakeAbsolutePath
(
runtime
.
GOOS
,
m
.
globalPath
)
err
=
m
.
mounter
.
Mount
(
globalPath
,
dir
,
""
,
o
ptions
)
err
=
m
.
mounter
.
Mount
(
globalPath
,
dir
,
""
,
mountO
ptions
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Mount of volume %s failed: %v"
,
dir
,
err
)
glog
.
Errorf
(
"Mount of volume %s failed: %v"
,
dir
,
err
)
notMnt
,
mntErr
:=
m
.
mounter
.
IsNotMountPoint
(
dir
)
notMnt
,
mntErr
:=
m
.
mounter
.
IsNotMountPoint
(
dir
)
...
...
pkg/volume/local/local_test.go
View file @
f7338373
...
@@ -131,7 +131,7 @@ func getDeviceMountablePluginWithBlockPath(t *testing.T, isBlockDevice bool) (st
...
@@ -131,7 +131,7 @@ func getDeviceMountablePluginWithBlockPath(t *testing.T, isBlockDevice bool) (st
return
tmpDir
,
plug
return
tmpDir
,
plug
}
}
func
getTestVolume
(
readOnly
bool
,
path
string
,
isBlock
bool
)
*
volume
.
Spec
{
func
getTestVolume
(
readOnly
bool
,
path
string
,
isBlock
bool
,
mountOptions
[]
string
)
*
volume
.
Spec
{
pv
:=
&
v1
.
PersistentVolume
{
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testPVName
,
Name
:
testPVName
,
...
@@ -142,6 +142,7 @@ func getTestVolume(readOnly bool, path string, isBlock bool) *volume.Spec {
...
@@ -142,6 +142,7 @@ func getTestVolume(readOnly bool, path string, isBlock bool) *volume.Spec {
Path
:
path
,
Path
:
path
,
},
},
},
},
MountOptions
:
mountOptions
,
},
},
}
}
...
@@ -156,7 +157,7 @@ func TestCanSupport(t *testing.T) {
...
@@ -156,7 +157,7 @@ func TestCanSupport(t *testing.T) {
tmpDir
,
plug
:=
getPlugin
(
t
)
tmpDir
,
plug
:=
getPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
if
!
plug
.
CanSupport
(
getTestVolume
(
false
,
tmpDir
,
false
))
{
if
!
plug
.
CanSupport
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
))
{
t
.
Errorf
(
"Expected true"
)
t
.
Errorf
(
"Expected true"
)
}
}
}
}
...
@@ -182,7 +183,7 @@ func TestGetVolumeName(t *testing.T) {
...
@@ -182,7 +183,7 @@ func TestGetVolumeName(t *testing.T) {
tmpDir
,
plug
:=
getPersistentPlugin
(
t
)
tmpDir
,
plug
:=
getPersistentPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
volName
,
err
:=
plug
.
GetVolumeName
(
getTestVolume
(
false
,
tmpDir
,
false
))
volName
,
err
:=
plug
.
GetVolumeName
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get volume name: %v"
,
err
)
t
.
Errorf
(
"Failed to get volume name: %v"
,
err
)
}
}
...
@@ -196,7 +197,7 @@ func TestInvalidLocalPath(t *testing.T) {
...
@@ -196,7 +197,7 @@ func TestInvalidLocalPath(t *testing.T) {
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
"/no/backsteps/allowed/.."
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
"/no/backsteps/allowed/.."
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -218,7 +219,7 @@ func TestBlockDeviceGlobalPathAndMountDevice(t *testing.T) {
...
@@ -218,7 +219,7 @@ func TestBlockDeviceGlobalPathAndMountDevice(t *testing.T) {
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
}
}
pvSpec
:=
getTestVolume
(
false
,
tmpBlockDir
,
false
)
pvSpec
:=
getTestVolume
(
false
,
tmpBlockDir
,
false
,
nil
)
expectedGlobalPath
:=
filepath
.
Join
(
tmpBlockDir
,
testBlockFormattingToFSGlobalPath
)
expectedGlobalPath
:=
filepath
.
Join
(
tmpBlockDir
,
testBlockFormattingToFSGlobalPath
)
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
...
@@ -264,7 +265,7 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
...
@@ -264,7 +265,7 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
}
}
pvSpec
:=
getTestVolume
(
false
,
tmpFSDir
,
false
)
pvSpec
:=
getTestVolume
(
false
,
tmpFSDir
,
false
,
nil
)
expectedGlobalPath
:=
tmpFSDir
expectedGlobalPath
:=
tmpFSDir
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
...
@@ -294,7 +295,7 @@ func TestMountUnmount(t *testing.T) {
...
@@ -294,7 +295,7 @@ func TestMountUnmount(t *testing.T) {
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
}
}
...
@@ -347,7 +348,7 @@ func TestMapUnmap(t *testing.T) {
...
@@ -347,7 +348,7 @@ func TestMapUnmap(t *testing.T) {
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
volSpec
:=
getTestVolume
(
false
,
tmpDir
,
true
/*isBlock*/
)
volSpec
:=
getTestVolume
(
false
,
tmpDir
,
true
/*isBlock*/
,
nil
)
mapper
,
err
:=
plug
.
NewBlockVolumeMapper
(
volSpec
,
pod
,
volume
.
VolumeOptions
{})
mapper
,
err
:=
plug
.
NewBlockVolumeMapper
(
volSpec
,
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
...
@@ -399,7 +400,7 @@ func TestMapUnmap(t *testing.T) {
...
@@ -399,7 +400,7 @@ func TestMapUnmap(t *testing.T) {
}
}
func
testFSGroupMount
(
plug
volume
.
VolumePlugin
,
pod
*
v1
.
Pod
,
tmpDir
string
,
fsGroup
int64
)
error
{
func
testFSGroupMount
(
plug
volume
.
VolumePlugin
,
pod
*
v1
.
Pod
,
tmpDir
string
,
fsGroup
int64
)
error
{
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -501,13 +502,40 @@ func TestConstructBlockVolumeSpec(t *testing.T) {
...
@@ -501,13 +502,40 @@ func TestConstructBlockVolumeSpec(t *testing.T) {
}
}
}
}
func
TestMountOptions
(
t
*
testing
.
T
)
{
tmpDir
,
plug
:=
getPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
,
[]
string
{
"test-option"
}),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
}
if
mounter
==
nil
{
t
.
Fatalf
(
"Got a nil Mounter"
)
}
// Wrap with FakeMounter.
fakeMounter
:=
&
mount
.
FakeMounter
{}
mounter
.
(
*
localVolumeMounter
)
.
mounter
=
fakeMounter
if
err
:=
mounter
.
SetUp
(
nil
);
err
!=
nil
{
t
.
Errorf
(
"Expected success, got: %v"
,
err
)
}
mountOptions
:=
fakeMounter
.
MountPoints
[
0
]
.
Opts
expectedMountOptions
:=
[]
string
{
"bind"
,
"test-option"
}
if
!
reflect
.
DeepEqual
(
mountOptions
,
expectedMountOptions
)
{
t
.
Errorf
(
"Expected mount options to be %v got %v"
,
expectedMountOptions
,
mountOptions
)
}
}
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
func
TestPersistentClaimReadOnlyFlag
(
t
*
testing
.
T
)
{
tmpDir
,
plug
:=
getPlugin
(
t
)
tmpDir
,
plug
:=
getPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
// Read only == true
// Read only == true
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
true
,
tmpDir
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
true
,
tmpDir
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
}
}
...
@@ -519,7 +547,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
...
@@ -519,7 +547,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
}
}
// Read only == false
// Read only == false
mounter
,
err
=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Mounter: %v"
,
err
)
}
}
...
@@ -540,7 +568,7 @@ func TestUnsupportedPlugins(t *testing.T) {
...
@@ -540,7 +568,7 @@ func TestUnsupportedPlugins(t *testing.T) {
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
nil
/* prober */
,
volumetest
.
NewFakeVolumeHost
(
tmpDir
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
nil
/* prober */
,
volumetest
.
NewFakeVolumeHost
(
tmpDir
,
nil
,
nil
))
spec
:=
getTestVolume
(
false
,
tmpDir
,
false
)
spec
:=
getTestVolume
(
false
,
tmpDir
,
false
,
nil
)
recyclePlug
,
err
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
recyclePlug
,
err
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
if
err
==
nil
&&
recyclePlug
!=
nil
{
if
err
==
nil
&&
recyclePlug
!=
nil
{
...
@@ -573,7 +601,7 @@ func TestFilterPodMounts(t *testing.T) {
...
@@ -573,7 +601,7 @@ func TestFilterPodMounts(t *testing.T) {
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
),
pod
,
volume
.
VolumeOptions
{})
mounter
,
err
:=
plug
.
NewMounter
(
getTestVolume
(
false
,
tmpDir
,
false
,
nil
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
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