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