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
cb547f4b
Commit
cb547f4b
authored
May 29, 2015
by
markturansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RecyclableVolumePlugin interfaces
parent
2829fadf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
4 deletions
+65
-4
plugins.go
pkg/volume/plugins.go
+37
-2
testing.go
pkg/volume/testing.go
+18
-0
volume.go
pkg/volume/volume.go
+10
-2
No files found.
pkg/volume/plugins.go
View file @
cb547f4b
...
@@ -79,6 +79,15 @@ type PersistentVolumePlugin interface {
...
@@ -79,6 +79,15 @@ type PersistentVolumePlugin interface {
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
}
}
// RecyclableVolumePlugin is an extended interface of VolumePlugin and is used
// by persistent volumes that want to be recycled before being made available again to new claims
type
RecyclableVolumePlugin
interface
{
VolumePlugin
// NewRecycler creates a new volume.Recycler which knows how to reclaim this resource
// after the volume's release from a PersistentVolumeClaim
NewRecycler
(
spec
*
Spec
)
(
Recycler
,
error
)
}
// VolumeHost is an interface that plugins can use to access the kubelet.
// VolumeHost is an interface that plugins can use to access the kubelet.
type
VolumeHost
interface
{
type
VolumeHost
interface
{
// GetPluginDir returns the absolute path to a directory under which
// GetPluginDir returns the absolute path to a directory under which
...
@@ -217,7 +226,20 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
...
@@ -217,7 +226,20 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
return
pm
.
plugins
[
matches
[
0
]],
nil
return
pm
.
plugins
[
matches
[
0
]],
nil
}
}
// FindPluginByName fetches a plugin by name or by legacy name. If no plugin
// FindPersistentPluginBySpec looks for a persistent volume plugin that can support a given volume
// specification. If no plugin is found, return an error
func
(
pm
*
VolumePluginMgr
)
FindPersistentPluginBySpec
(
spec
*
Spec
)
(
PersistentVolumePlugin
,
error
)
{
volumePlugin
,
err
:=
pm
.
FindPluginBySpec
(
spec
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Could not find volume plugin for spec: %+v"
,
spec
)
}
if
persistentVolumePlugin
,
ok
:=
volumePlugin
.
(
PersistentVolumePlugin
);
ok
{
return
persistentVolumePlugin
,
nil
}
return
nil
,
fmt
.
Errorf
(
"no persistent volume plugin matched"
)
}
// FindPersistentPluginByName fetches a persistent volume plugin by name. If no plugin
// is found, returns error.
// is found, returns error.
func
(
pm
*
VolumePluginMgr
)
FindPersistentPluginByName
(
name
string
)
(
PersistentVolumePlugin
,
error
)
{
func
(
pm
*
VolumePluginMgr
)
FindPersistentPluginByName
(
name
string
)
(
PersistentVolumePlugin
,
error
)
{
volumePlugin
,
err
:=
pm
.
FindPluginByName
(
name
)
volumePlugin
,
err
:=
pm
.
FindPluginByName
(
name
)
...
@@ -227,5 +249,18 @@ func (pm *VolumePluginMgr) FindPersistentPluginByName(name string) (PersistentVo
...
@@ -227,5 +249,18 @@ func (pm *VolumePluginMgr) FindPersistentPluginByName(name string) (PersistentVo
if
persistentVolumePlugin
,
ok
:=
volumePlugin
.
(
PersistentVolumePlugin
);
ok
{
if
persistentVolumePlugin
,
ok
:=
volumePlugin
.
(
PersistentVolumePlugin
);
ok
{
return
persistentVolumePlugin
,
nil
return
persistentVolumePlugin
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no persistent volume plugin matched"
)
return
nil
,
fmt
.
Errorf
(
"no persistent volume plugin matched: %+v"
)
}
// FindRecyclablePluginByName fetches a persistent volume plugin by name. If no plugin
// is found, returns error.
func
(
pm
*
VolumePluginMgr
)
FindRecyclablePluginBySpec
(
spec
*
Spec
)
(
RecyclableVolumePlugin
,
error
)
{
volumePlugin
,
err
:=
pm
.
FindPluginBySpec
(
spec
)
if
err
!=
nil
{
return
nil
,
err
}
if
recyclableVolumePlugin
,
ok
:=
volumePlugin
.
(
RecyclableVolumePlugin
);
ok
{
return
recyclableVolumePlugin
,
nil
}
return
nil
,
fmt
.
Errorf
(
"no recyclable volume plugin matched"
)
}
}
pkg/volume/testing.go
View file @
cb547f4b
...
@@ -82,6 +82,7 @@ type FakeVolumePlugin struct {
...
@@ -82,6 +82,7 @@ type FakeVolumePlugin struct {
}
}
var
_
VolumePlugin
=
&
FakeVolumePlugin
{}
var
_
VolumePlugin
=
&
FakeVolumePlugin
{}
var
_
RecyclableVolumePlugin
=
&
FakeVolumePlugin
{}
func
(
plugin
*
FakeVolumePlugin
)
Init
(
host
VolumeHost
)
{
func
(
plugin
*
FakeVolumePlugin
)
Init
(
host
VolumeHost
)
{
plugin
.
Host
=
host
plugin
.
Host
=
host
...
@@ -104,6 +105,10 @@ func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID, mou
...
@@ -104,6 +105,10 @@ func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID, mou
return
&
FakeVolume
{
podUID
,
volName
,
plugin
},
nil
return
&
FakeVolume
{
podUID
,
volName
,
plugin
},
nil
}
}
func
(
plugin
*
FakeVolumePlugin
)
NewRecycler
(
spec
*
Spec
)
(
Recycler
,
error
)
{
return
&
FakeRecycler
{
"/attributesTransferredFromSpec"
},
nil
}
func
(
plugin
*
FakeVolumePlugin
)
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
{
func
(
plugin
*
FakeVolumePlugin
)
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
{
return
[]
api
.
PersistentVolumeAccessMode
{}
return
[]
api
.
PersistentVolumeAccessMode
{}
}
}
...
@@ -133,3 +138,16 @@ func (fv *FakeVolume) TearDown() error {
...
@@ -133,3 +138,16 @@ func (fv *FakeVolume) TearDown() error {
func
(
fv
*
FakeVolume
)
TearDownAt
(
dir
string
)
error
{
func
(
fv
*
FakeVolume
)
TearDownAt
(
dir
string
)
error
{
return
os
.
RemoveAll
(
dir
)
return
os
.
RemoveAll
(
dir
)
}
}
type
FakeRecycler
struct
{
path
string
}
func
(
fr
*
FakeRecycler
)
Recycle
()
error
{
// nil is success, else error
return
nil
}
func
(
fr
*
FakeRecycler
)
GetPath
()
string
{
return
fr
.
path
}
pkg/volume/volume.go
View file @
cb547f4b
...
@@ -29,7 +29,7 @@ type Volume interface {
...
@@ -29,7 +29,7 @@ type Volume interface {
GetPath
()
string
GetPath
()
string
}
}
// Builder interface provides method to set up/mount the volume.
// Builder interface provides method
s
to set up/mount the volume.
type
Builder
interface
{
type
Builder
interface
{
// Uses Interface to provide the path for Docker binds.
// Uses Interface to provide the path for Docker binds.
Volume
Volume
...
@@ -43,7 +43,7 @@ type Builder interface {
...
@@ -43,7 +43,7 @@ type Builder interface {
SetUpAt
(
dir
string
)
error
SetUpAt
(
dir
string
)
error
}
}
// Cleaner interface provides method to cleanup/unmount the volumes.
// Cleaner interface provides method
s
to cleanup/unmount the volumes.
type
Cleaner
interface
{
type
Cleaner
interface
{
Volume
Volume
// TearDown unmounts the volume from a self-determined directory and
// TearDown unmounts the volume from a self-determined directory and
...
@@ -54,6 +54,14 @@ type Cleaner interface {
...
@@ -54,6 +54,14 @@ type Cleaner interface {
TearDownAt
(
dir
string
)
error
TearDownAt
(
dir
string
)
error
}
}
// Recycler provides methods to reclaim the volume resource.
type
Recycler
interface
{
Volume
// Recycle reclaims the resource. Calls to this method should block until the recycling task is complete.
// Any error returned indicates the volume has failed to be reclaimed. A nil return indicates success.
Recycle
()
error
}
func
RenameDirectory
(
oldPath
,
newName
string
)
(
string
,
error
)
{
func
RenameDirectory
(
oldPath
,
newName
string
)
(
string
,
error
)
{
newPath
,
err
:=
ioutil
.
TempDir
(
path
.
Dir
(
oldPath
),
newName
)
newPath
,
err
:=
ioutil
.
TempDir
(
path
.
Dir
(
oldPath
),
newName
)
if
err
!=
nil
{
if
err
!=
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