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
d09d121b
Commit
d09d121b
authored
Jul 23, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11572 from jiangyaoguo/new-builder-cleaner-for-nfs
Refactor nfs volume to seperate builder and cleaner
parents
dc59c99d
612f68f8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
52 deletions
+61
-52
nfs.go
pkg/volume/nfs/nfs.go
+60
-51
nfs_test.go
pkg/volume/nfs/nfs_test.go
+1
-1
No files found.
pkg/volume/nfs/nfs.go
View file @
d09d121b
...
@@ -82,16 +82,16 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
...
@@ -82,16 +82,16 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
}
else
{
}
else
{
source
=
spec
.
PersistentVolumeSource
.
NFS
source
=
spec
.
PersistentVolumeSource
.
NFS
}
}
return
&
nfs
{
return
&
nfsBuilder
{
nfs
:
&
nfs
{
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
server
:
source
.
Server
,
exportPath
:
source
.
Path
,
readOnly
:
source
.
ReadOnly
,
mounter
:
mounter
,
mounter
:
mounter
,
pod
:
pod
,
pod
:
pod
,
plugin
:
plugin
,
plugin
:
plugin
,
},
nil
},
server
:
source
.
Server
,
exportPath
:
source
.
Path
,
readOnly
:
source
.
ReadOnly
},
nil
}
}
func
(
plugin
*
nfsPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
nfsPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
...
@@ -99,59 +99,49 @@ func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID, mounter mo
...
@@ -99,59 +99,49 @@ func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID, mounter mo
}
}
func
(
plugin
*
nfsPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
nfsPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
return
&
nfs
{
return
&
nfs
Cleaner
{
&
nfs
{
volName
:
volName
,
volName
:
volName
,
server
:
""
,
exportPath
:
""
,
readOnly
:
false
,
mounter
:
mounter
,
mounter
:
mounter
,
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}},
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}},
plugin
:
plugin
,
plugin
:
plugin
,
},
nil
}
}
,
nil
}
}
func
(
plugin
*
nfsPlugin
)
NewRecycler
(
spec
*
volume
.
Spec
)
(
volume
.
Recycler
,
error
)
{
func
(
plugin
*
nfsPlugin
)
NewRecycler
(
spec
*
volume
.
Spec
)
(
volume
.
Recycler
,
error
)
{
return
plugin
.
newRecyclerFunc
(
spec
,
plugin
.
host
)
return
plugin
.
newRecyclerFunc
(
spec
,
plugin
.
host
)
}
}
func
newRecycler
(
spec
*
volume
.
Spec
,
host
volume
.
VolumeHost
)
(
volume
.
Recycler
,
error
)
{
if
spec
.
VolumeSource
.
HostPath
!=
nil
{
return
&
nfsRecycler
{
name
:
spec
.
Name
,
server
:
spec
.
VolumeSource
.
NFS
.
Server
,
path
:
spec
.
VolumeSource
.
NFS
.
Path
,
host
:
host
,
},
nil
}
else
{
return
&
nfsRecycler
{
name
:
spec
.
Name
,
server
:
spec
.
PersistentVolumeSource
.
NFS
.
Server
,
path
:
spec
.
PersistentVolumeSource
.
NFS
.
Path
,
host
:
host
,
},
nil
}
}
// NFS volumes represent a bare host file or directory mount of an NFS export.
// NFS volumes represent a bare host file or directory mount of an NFS export.
type
nfs
struct
{
type
nfs
struct
{
volName
string
volName
string
pod
*
api
.
Pod
pod
*
api
.
Pod
server
string
exportPath
string
readOnly
bool
mounter
mount
.
Interface
mounter
mount
.
Interface
plugin
*
nfsPlugin
plugin
*
nfsPlugin
// decouple creating recyclers by deferring to a function. Allows for easier testing.
// decouple creating recyclers by deferring to a function. Allows for easier testing.
newRecyclerFunc
func
(
spec
*
volume
.
Spec
,
host
volume
.
VolumeHost
)
(
volume
.
Recycler
,
error
)
newRecyclerFunc
func
(
spec
*
volume
.
Spec
,
host
volume
.
VolumeHost
)
(
volume
.
Recycler
,
error
)
}
}
func
(
nfsVolume
*
nfs
)
GetPath
()
string
{
name
:=
nfsPluginName
return
nfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
nfsVolume
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
nfsVolume
.
volName
)
}
type
nfsBuilder
struct
{
*
nfs
server
string
exportPath
string
readOnly
bool
}
var
_
volume
.
Builder
=
&
nfsBuilder
{}
// SetUp attaches the disk and bind mounts to the volume path.
// SetUp attaches the disk and bind mounts to the volume path.
func
(
nfsVolume
*
nfs
)
SetUp
()
error
{
func
(
b
*
nfsBuilder
)
SetUp
()
error
{
return
nfsVolume
.
SetUpAt
(
nfsVolume
.
GetPath
())
return
b
.
SetUpAt
(
b
.
GetPath
())
}
}
func
(
nfsVolume
*
nfs
)
SetUpAt
(
dir
string
)
error
{
func
(
b
*
nfsBuilder
)
SetUpAt
(
dir
string
)
error
{
mountpoint
,
err
:=
nfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
err
:=
b
.
mounter
.
IsMountPoint
(
dir
)
glog
.
V
(
4
)
.
Infof
(
"NFS mount set up: %s %v %v"
,
dir
,
mountpoint
,
err
)
glog
.
V
(
4
)
.
Infof
(
"NFS mount set up: %s %v %v"
,
dir
,
mountpoint
,
err
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
err
return
err
...
@@ -160,24 +150,24 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
...
@@ -160,24 +150,24 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
return
nil
return
nil
}
}
os
.
MkdirAll
(
dir
,
0750
)
os
.
MkdirAll
(
dir
,
0750
)
source
:=
fmt
.
Sprintf
(
"%s:%s"
,
nfsVolume
.
server
,
nfsVolume
.
exportPath
)
source
:=
fmt
.
Sprintf
(
"%s:%s"
,
b
.
server
,
b
.
exportPath
)
options
:=
[]
string
{}
options
:=
[]
string
{}
if
nfsVolume
.
readOnly
{
if
b
.
readOnly
{
options
=
append
(
options
,
"ro"
)
options
=
append
(
options
,
"ro"
)
}
}
err
=
nfsVolume
.
mounter
.
Mount
(
source
,
dir
,
"nfs"
,
options
)
err
=
b
.
mounter
.
Mount
(
source
,
dir
,
"nfs"
,
options
)
if
err
!=
nil
{
if
err
!=
nil
{
mountpoint
,
mntErr
:=
nfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
mntErr
:=
b
.
mounter
.
IsMountPoint
(
dir
)
if
mntErr
!=
nil
{
if
mntErr
!=
nil
{
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
return
err
return
err
}
}
if
mountpoint
{
if
mountpoint
{
if
mntErr
=
nfsVolume
.
mounter
.
Unmount
(
dir
);
mntErr
!=
nil
{
if
mntErr
=
b
.
mounter
.
Unmount
(
dir
);
mntErr
!=
nil
{
glog
.
Errorf
(
"Failed to unmount: %v"
,
mntErr
)
glog
.
Errorf
(
"Failed to unmount: %v"
,
mntErr
)
return
err
return
err
}
}
mountpoint
,
mntErr
:=
nfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
mntErr
:=
b
.
mounter
.
IsMountPoint
(
dir
)
if
mntErr
!=
nil
{
if
mntErr
!=
nil
{
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
return
err
return
err
...
@@ -194,17 +184,18 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
...
@@ -194,17 +184,18 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
return
nil
return
nil
}
}
func
(
nfsVolume
*
nfs
)
GetPath
()
string
{
type
nfsCleaner
struct
{
name
:=
nfsPluginName
*
nfs
return
nfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
nfsVolume
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
nfsVolume
.
volName
)
}
}
func
(
nfsVolume
*
nfs
)
TearDown
()
error
{
var
_
volume
.
Cleaner
=
&
nfsCleaner
{}
return
nfsVolume
.
TearDownAt
(
nfsVolume
.
GetPath
())
func
(
c
*
nfsCleaner
)
TearDown
()
error
{
return
c
.
TearDownAt
(
c
.
GetPath
())
}
}
func
(
nfsVolume
*
nfs
)
TearDownAt
(
dir
string
)
error
{
func
(
c
*
nfsCleaner
)
TearDownAt
(
dir
string
)
error
{
mountpoint
,
err
:=
nfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
err
:=
c
.
mounter
.
IsMountPoint
(
dir
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error checking IsMountPoint: %v"
,
err
)
glog
.
Errorf
(
"Error checking IsMountPoint: %v"
,
err
)
return
err
return
err
...
@@ -213,11 +204,11 @@ func (nfsVolume *nfs) TearDownAt(dir string) error {
...
@@ -213,11 +204,11 @@ func (nfsVolume *nfs) TearDownAt(dir string) error {
return
os
.
Remove
(
dir
)
return
os
.
Remove
(
dir
)
}
}
if
err
:=
nfsVolume
.
mounter
.
Unmount
(
dir
);
err
!=
nil
{
if
err
:=
c
.
mounter
.
Unmount
(
dir
);
err
!=
nil
{
glog
.
Errorf
(
"Unmounting failed: %v"
,
err
)
glog
.
Errorf
(
"Unmounting failed: %v"
,
err
)
return
err
return
err
}
}
mountpoint
,
mntErr
:=
nfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
mntErr
:=
c
.
mounter
.
IsMountPoint
(
dir
)
if
mntErr
!=
nil
{
if
mntErr
!=
nil
{
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
glog
.
Errorf
(
"IsMountpoint check failed: %v"
,
mntErr
)
return
mntErr
return
mntErr
...
@@ -231,6 +222,24 @@ func (nfsVolume *nfs) TearDownAt(dir string) error {
...
@@ -231,6 +222,24 @@ func (nfsVolume *nfs) TearDownAt(dir string) error {
return
nil
return
nil
}
}
func
newRecycler
(
spec
*
volume
.
Spec
,
host
volume
.
VolumeHost
)
(
volume
.
Recycler
,
error
)
{
if
spec
.
VolumeSource
.
HostPath
!=
nil
{
return
&
nfsRecycler
{
name
:
spec
.
Name
,
server
:
spec
.
VolumeSource
.
NFS
.
Server
,
path
:
spec
.
VolumeSource
.
NFS
.
Path
,
host
:
host
,
},
nil
}
else
{
return
&
nfsRecycler
{
name
:
spec
.
Name
,
server
:
spec
.
PersistentVolumeSource
.
NFS
.
Server
,
path
:
spec
.
PersistentVolumeSource
.
NFS
.
Path
,
host
:
host
,
},
nil
}
}
// nfsRecycler scrubs an NFS volume by running "rm -rf" on the volume in a pod.
// nfsRecycler scrubs an NFS volume by running "rm -rf" on the volume in a pod.
type
nfsRecycler
struct
{
type
nfsRecycler
struct
{
name
string
name
string
...
...
pkg/volume/nfs/nfs_test.go
View file @
d09d121b
...
@@ -141,7 +141,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
...
@@ -141,7 +141,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
}
}
}
}
if
builder
.
(
*
nfs
)
.
readOnly
{
if
builder
.
(
*
nfs
Builder
)
.
readOnly
{
t
.
Errorf
(
"The volume source should not be read-only and it is."
)
t
.
Errorf
(
"The volume source should not be read-only and it is."
)
}
}
if
len
(
fake
.
Log
)
!=
1
{
if
len
(
fake
.
Log
)
!=
1
{
...
...
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