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
8bb0ae9f
Commit
8bb0ae9f
authored
Jul 23, 2015
by
jiangyaoguo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refector glusterfs volume to seperate builder and cleaner
parent
8cbe9c99
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
32 deletions
+46
-32
glusterfs.go
pkg/volume/glusterfs/glusterfs.go
+46
-32
No files found.
pkg/volume/glusterfs/glusterfs.go
View file @
8bb0ae9f
...
...
@@ -87,16 +87,17 @@ func (plugin *glusterfsPlugin) getGlusterVolumeSource(spec *volume.Spec) *api.Gl
func
(
plugin
*
glusterfsPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
ep
*
api
.
Endpoints
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
,
exe
exec
.
Interface
)
(
volume
.
Builder
,
error
)
{
source
:=
plugin
.
getGlusterVolumeSource
(
spec
)
return
&
glusterfs
{
volName
:
spec
.
Name
,
return
&
glusterfsBuilder
{
glusterfs
:
&
glusterfs
{
volName
:
spec
.
Name
,
mounter
:
mounter
,
pod
:
pod
,
plugin
:
plugin
,
},
hosts
:
ep
,
path
:
source
.
Path
,
readonly
:
source
.
ReadOnly
,
mounter
:
mounter
,
exe
:
exe
,
pod
:
pod
,
plugin
:
plugin
,
},
nil
exe
:
exe
},
nil
}
func
(
plugin
*
glusterfsPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
...
...
@@ -104,33 +105,39 @@ func (plugin *glusterfsPlugin) NewCleaner(volName string, podUID types.UID, moun
}
func
(
plugin
*
glusterfsPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
return
&
glusterfs
{
return
&
glusterfs
Cleaner
{
&
glusterfs
{
volName
:
volName
,
mounter
:
mounter
,
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}},
plugin
:
plugin
,
},
nil
}
}
,
nil
}
// Glusterfs volumes represent a bare host file or directory mount of an Glusterfs export.
type
glusterfs
struct
{
volName
string
pod
*
api
.
Pod
volName
string
pod
*
api
.
Pod
mounter
mount
.
Interface
plugin
*
glusterfsPlugin
}
type
glusterfsBuilder
struct
{
*
glusterfs
hosts
*
api
.
Endpoints
path
string
readonly
bool
mounter
mount
.
Interface
exe
exec
.
Interface
plugin
*
glusterfsPlugin
}
var
_
volume
.
Builder
=
&
glusterfsBuilder
{}
// SetUp attaches the disk and bind mounts to the volume path.
func
(
glusterfsVolume
*
glusterfs
)
SetUp
()
error
{
return
glusterfsVolume
.
SetUpAt
(
glusterfsVolume
.
GetPath
())
func
(
b
*
glusterfsBuilder
)
SetUp
()
error
{
return
b
.
SetUpAt
(
b
.
GetPath
())
}
func
(
glusterfsVolume
*
glusterfs
)
SetUpAt
(
dir
string
)
error
{
mountpoint
,
err
:=
glusterfsVolume
.
mounter
.
IsMountPoint
(
dir
)
func
(
b
*
glusterfsBuilder
)
SetUpAt
(
dir
string
)
error
{
mountpoint
,
err
:=
b
.
mounter
.
IsMountPoint
(
dir
)
glog
.
V
(
4
)
.
Infof
(
"Glusterfs: mount set up: %s %v %v"
,
dir
,
mountpoint
,
err
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
err
...
...
@@ -140,13 +147,14 @@ func (glusterfsVolume *glusterfs) SetUpAt(dir string) error {
}
os
.
MkdirAll
(
dir
,
0750
)
err
=
glusterfsVolume
.
setUpAtInternal
(
dir
)
err
=
b
.
setUpAtInternal
(
dir
)
if
err
==
nil
{
return
nil
}
// Cleanup upon failure.
glusterfsVolume
.
cleanup
(
dir
)
c
:=
&
glusterfsCleaner
{
b
.
glusterfs
}
c
.
cleanup
(
dir
)
return
err
}
...
...
@@ -155,16 +163,22 @@ func (glusterfsVolume *glusterfs) GetPath() string {
return
glusterfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
glusterfsVolume
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
glusterfsVolume
.
volName
)
}
func
(
glusterfsVolume
*
glusterfs
)
TearDown
()
error
{
return
glusterfsVolume
.
TearDownAt
(
glusterfsVolume
.
GetPath
())
type
glusterfsCleaner
struct
{
*
glusterfs
}
var
_
volume
.
Cleaner
=
&
glusterfsCleaner
{}
func
(
c
*
glusterfsCleaner
)
TearDown
()
error
{
return
c
.
TearDownAt
(
c
.
GetPath
())
}
func
(
glusterfsVolume
*
glusterfs
)
TearDownAt
(
dir
string
)
error
{
return
glusterfsVolume
.
cleanup
(
dir
)
func
(
c
*
glusterfsCleaner
)
TearDownAt
(
dir
string
)
error
{
return
c
.
cleanup
(
dir
)
}
func
(
glusterfsVolume
*
glusterfs
)
cleanup
(
dir
string
)
error
{
mountpoint
,
err
:=
glusterfsVolume
.
mounter
.
IsMountPoint
(
dir
)
func
(
c
*
glusterfsCleaner
)
cleanup
(
dir
string
)
error
{
mountpoint
,
err
:=
c
.
mounter
.
IsMountPoint
(
dir
)
if
err
!=
nil
{
glog
.
Errorf
(
"Glusterfs: Error checking IsMountPoint: %v"
,
err
)
return
err
...
...
@@ -173,11 +187,11 @@ func (glusterfsVolume *glusterfs) cleanup(dir string) error {
return
os
.
RemoveAll
(
dir
)
}
if
err
:=
glusterfsVolume
.
mounter
.
Unmount
(
dir
);
err
!=
nil
{
if
err
:=
c
.
mounter
.
Unmount
(
dir
);
err
!=
nil
{
glog
.
Errorf
(
"Glusterfs: Unmounting failed: %v"
,
err
)
return
err
}
mountpoint
,
mntErr
:=
glusterfsVolume
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
mntErr
:=
c
.
mounter
.
IsMountPoint
(
dir
)
if
mntErr
!=
nil
{
glog
.
Errorf
(
"Glusterfs: IsMountpoint check failed: %v"
,
mntErr
)
return
mntErr
...
...
@@ -191,21 +205,21 @@ func (glusterfsVolume *glusterfs) cleanup(dir string) error {
return
nil
}
func
(
glusterfsVolume
*
glusterfs
)
setUpAtInternal
(
dir
string
)
error
{
func
(
b
*
glusterfsBuilder
)
setUpAtInternal
(
dir
string
)
error
{
var
errs
error
options
:=
[]
string
{}
if
glusterfsVolume
.
readonly
{
if
b
.
readonly
{
options
=
append
(
options
,
"ro"
)
}
l
:=
len
(
glusterfsVolume
.
hosts
.
Subsets
)
l
:=
len
(
b
.
hosts
.
Subsets
)
// Avoid mount storm, pick a host randomly.
start
:=
rand
.
Int
()
%
l
// Iterate all hosts until mount succeeds.
for
i
:=
start
;
i
<
start
+
l
;
i
++
{
hostIP
:=
glusterfsVolume
.
hosts
.
Subsets
[
i
%
l
]
.
Addresses
[
0
]
.
IP
errs
=
glusterfsVolume
.
mounter
.
Mount
(
hostIP
+
":"
+
glusterfsVolume
.
path
,
dir
,
"glusterfs"
,
options
)
hostIP
:=
b
.
hosts
.
Subsets
[
i
%
l
]
.
Addresses
[
0
]
.
IP
errs
=
b
.
mounter
.
Mount
(
hostIP
+
":"
+
b
.
path
,
dir
,
"glusterfs"
,
options
)
if
errs
==
nil
{
return
nil
}
...
...
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